Skip to content

Instantly share code, notes, and snippets.

@atimin
Created October 20, 2011 16:07
Show Gist options
  • Select an option

  • Save atimin/1301541 to your computer and use it in GitHub Desktop.

Select an option

Save atimin/1301541 to your computer and use it in GitHub Desktop.
For articles about Lipa #1
require "lipa"
store = Lipa::Tree.new :store do
kind :category, :for => :node do
unit_count Proc.new {
count = 0
children.values.each do |u|
count += u.count if u.kind == "unit"
end
count
}
total_cost Proc.new {
total_cost = 0
children.values.each do |u|
total_cost += u.count * u.cost if u.kind == "unit"
end
total_cost
}
end
kind :unit, :for => :node do
count 0
cost 0.0
with_nds Proc.new{cost * 1.18}
end
category :electorinics do
category :video do
with :label => "Sony" do
unit :tv_1 do
count 231
part_number "123-567-a"
cost 100.0
end
unit :tv_2 do
count 27
part_number "123-567-b"
cost 199.0
end
end
unit :tv_3 do
count 98
part_number "123-567-c"
cost 299.0
label "Samsung"
end
end
category :audio do
unit :player_1 do
count 193
part_number "123-567-d"
cost 99.0
label "Apple"
end
end
end
end
puts store.electorinics.video.unit_count
puts store.electorinics.video.total_cost
require "lipa"
store = Lipa::Tree.new :store do
kind :category, :for => :node
kind :unit, :for => :node
category :electorinics do
category :video do
with :label => "Sony" do
unit :tv_1 do
count 231
part_number "123-567-a"
cost 100.0
end
unit :tv_2 do
count 27
part_number "123-567-b"
cost 199.0
end
end
unit :tv_3 do
count 98
part_number "123-567-c"
cost 299.0
label "Samsung"
end
end
category :audio do
unit :player_1 do
count 193
part_number "123-567-d"
cost 99.0
label "Apple"
end
end
end
end
puts store.electorinics.video.tv_1.label
puts store.electorinics.audio.player_1.cost
puts store.electorinics.video.name
require "lipa"
store = Lipa::Tree.new :store do
node :electorinics do
node :video do
node :tv_1 do
count 231
part_number "123-567-a"
cost 100.0
label "Sony"
end
node :tv_2 do
count 27
part_number "123-567-b"
cost 199.0
label "Sony"
end
node :tv_3 do
count 98
part_number "123-567-c"
cost 299.0
label "Samsung"
end
end
node :audio do
node :player_1 do
count 193
part_number "123-567-d"
cost 99.0
label "Apple"
end
end
end
end
puts store.electorinics.video.tv_1.label
puts store.electorinics.audio.player_1.cost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment