Class: Habdsl::Model::Location
- Inherits:
-
Object
- Object
- Habdsl::Model::Location
- Defined in:
- lib/habdsl/model/location.rb
Overview
Represents a location in the structure.
Instance Attribute Summary collapse
-
#equipments ⇒ Object
readonly
Returns the value of attribute equipments.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#sub_locations ⇒ Object
readonly
Returns the value of attribute sub_locations.
Instance Method Summary collapse
- #equipment(name:, label:, icon:, parent: nil) ⇒ Object
-
#initialize(name:, label:, icon:, parent: nil) ⇒ Location
constructor
A new instance of Location.
- #location(name:, label:, icon:, parent: nil) ⇒ Object
- #point ⇒ Object
- #to_s(parent_name = nil) ⇒ Object
Constructor Details
#initialize(name:, label:, icon:, parent: nil) ⇒ Location
Returns a new instance of Location.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/habdsl/model/location.rb', line 9 def initialize(name:, label:, icon:, parent: nil) validate!(name, "name") validate!(icon, "icon") @name = name @label = label @icon = icon @parent = parent @sub_locations = [] @equipments = [] end |
Instance Attribute Details
#equipments ⇒ Object (readonly)
Returns the value of attribute equipments.
7 8 9 |
# File 'lib/habdsl/model/location.rb', line 7 def equipments @equipments end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
7 8 9 |
# File 'lib/habdsl/model/location.rb', line 7 def icon @icon end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'lib/habdsl/model/location.rb', line 7 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/habdsl/model/location.rb', line 7 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/habdsl/model/location.rb', line 7 def parent @parent end |
#sub_locations ⇒ Object (readonly)
Returns the value of attribute sub_locations.
7 8 9 |
# File 'lib/habdsl/model/location.rb', line 7 def sub_locations @sub_locations end |
Instance Method Details
#equipment(name:, label:, icon:, parent: nil) ⇒ Object
27 28 29 30 31 |
# File 'lib/habdsl/model/location.rb', line 27 def equipment(name:, label:, icon:, parent: nil, &) eq = Equipment.new(name: name, label: label, icon: icon, parent: parent) eq.instance_eval(&) if block_given? @equipments << eq end |
#location(name:, label:, icon:, parent: nil) ⇒ Object
21 22 23 24 25 |
# File 'lib/habdsl/model/location.rb', line 21 def location(name:, label:, icon:, parent: nil, &) loc = Location.new(name: name, label: label, icon: icon, parent: parent) loc.instance_eval(&) if block_given? @sub_locations << loc end |
#point ⇒ Object
33 34 35 |
# File 'lib/habdsl/model/location.rb', line 33 def point(*) raise "Error: point cannot be directly under location. Use equipment to wrap it." end |
#to_s(parent_name = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/habdsl/model/location.rb', line 37 def to_s(parent_name = nil) result = "Group #{@name} \"#{@label}\" <#{@icon}>" result += format_parent(parent_name, @parent) result += " [\"Location\"]\n" @sub_locations.each {|sub_loc| result += sub_loc.to_s(@name) } @equipments.each {|eq| result += eq.to_s(@name) } result end |