Class: Autocad::Attributes
- Inherits:
-
Object
- Object
- Autocad::Attributes
- Includes:
- Enumerable
- Defined in:
- lib/autocad/block.rb,
lib/autocad/block_reference.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #each(&block) ⇒ Object
- #find_attribute(name) ⇒ Object
-
#initialize(blk, elements) ⇒ Attributes
constructor
A new instance of Attributes.
- #inspect ⇒ Object
- #keys ⇒ Object
- #to_h ⇒ Object
- #update_element(name, value) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(blk, elements) ⇒ Attributes
Returns a new instance of Attributes.
74 75 76 77 |
# File 'lib/autocad/block.rb', line 74 def initialize(blk, elements) @block = blk @elements = elements end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
72 73 74 |
# File 'lib/autocad/block.rb', line 72 def elements @elements end |
Instance Method Details
#[](name) ⇒ Object
95 96 97 98 |
# File 'lib/autocad/block.rb', line 95 def [](name) el = find_attribute(name) el.value if el end |
#[]=(name, value) ⇒ Object
100 101 102 |
# File 'lib/autocad/block.rb', line 100 def []=(name, value) update_element(name, value) end |
#each(&block) ⇒ Object
85 86 87 88 89 |
# File 'lib/autocad/block.rb', line 85 def each(&block) return to_enum(:each) unless block_given? elements.each(&block) end |
#find_attribute(name) ⇒ Object
91 92 93 |
# File 'lib/autocad/block.rb', line 91 def find_attribute(name) elements.find { |a| a.key == name } end |
#inspect ⇒ Object
120 121 122 |
# File 'lib/autocad/block.rb', line 120 def inspect "<Attributes count#{elements.size}>" end |
#keys ⇒ Object
104 105 106 |
# File 'lib/autocad/block.rb', line 104 def keys @elements.map { |e| e.key } end |
#to_h ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/autocad/block.rb', line 112 def to_h result = {} elements.each.with_object(result) do |a, h| h[a.key] = a.value end result end |
#update_element(name, value) ⇒ Object
79 80 81 82 83 |
# File 'lib/autocad/block.rb', line 79 def update_element(name, value) return unless att = find_attribute(name) att.update(value) end |
#values ⇒ Object
108 109 110 |
# File 'lib/autocad/block.rb', line 108 def values @elements.map { |e| e.value } end |