Class: HDLRuby::Properties
- Inherits:
-
Object
- Object
- HDLRuby::Properties
- Defined in:
- lib/HDLRuby/hruby_decorator.rb
Overview
A HDLRuby set of properties
Constant Summary collapse
- @@property_keys =
The set of all the property keys
Set.new
Instance Attribute Summary collapse
-
#owner ⇒ Object
readonly
The HDLRuby object owning of the set of properties.
Class Method Summary collapse
-
.each_key(&ruby_block) ⇒ Object
Iterator over all the property keys.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get a property.
-
#[]=(key, value) ⇒ Object
Add a property.
-
#clone ⇒ Object
Clones the properties: also clone the contents.
-
#each(&ruby_block) ⇒ Object
Iterate over the properties of the current set.
-
#each_with_key(key, &ruby_block) ⇒ Object
Iterate over each value associated with +key+.
-
#initialize(owner) ⇒ Properties
constructor
Create a new set of properties and attach it to HDLRuby object +owner+.
-
#key?(key) ⇒ Boolean
Tells if +key+ is present.
-
#merge(prop) ⇒ Object
Create a new set of properties by merging with +prop+.
Constructor Details
#initialize(owner) ⇒ Properties
Create a new set of properties and attach it to HDLRuby object +owner+.
158 159 160 161 162 163 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 158 def initialize(owner) # Attach the owner. @owner = owner # Create the set. @content = {} end |
Instance Attribute Details
#owner ⇒ Object (readonly)
The HDLRuby object owning of the set of properties
154 155 156 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 154 def owner @owner end |
Class Method Details
.each_key(&ruby_block) ⇒ Object
Iterator over all the property keys
Returns an enumerator if no ruby block is given.
221 222 223 224 225 226 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 221 def self.each_key(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each_key) unless ruby_block # A ruby block? Apply it on each input signal instance. @@property_keys.each(&ruby_block) end |
Instance Method Details
#[](key) ⇒ Object
Get a property
198 199 200 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 198 def [](key) return @content[key] end |
#[]=(key, value) ⇒ Object
Add a property
189 190 191 192 193 194 195 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 189 def []=(key,value) @@property_keys << key # Add an entry if not present. @content[key] = [] unless @content.key?(key) # Add the value to the entry. @content[key] << value end |
#clone ⇒ Object
Clones the properties: also clone the contents.
166 167 168 169 170 171 172 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 166 def clone result = Properties.new(owner) @contents.each do |k,vals| vals.each { |v| result[k] = v } end return result end |
#each(&ruby_block) ⇒ Object
Iterate over the properties of the current set.
Returns an enumerator if no ruby block is given.
211 212 213 214 215 216 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 211 def each(&ruby_block) # No ruby block? Return an enumerator. return to_enum(:each) unless ruby_block # A ruby block? Apply it on each input signal instance. @content.each(&ruby_block) end |
#each_with_key(key, &ruby_block) ⇒ Object
Iterate over each value associated with +key+.
203 204 205 206 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 203 def each_with_key(key,&ruby_block) return unless @content.key?(key) @content[key].each(&ruby_block) end |
#key?(key) ⇒ Boolean
Tells if +key+ is present.
184 185 186 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 184 def key?(key) @content.key?(key) end |
#merge(prop) ⇒ Object
Create a new set of properties by merging with +prop+
175 176 177 178 179 180 181 |
# File 'lib/HDLRuby/hruby_decorator.rb', line 175 def merge(prop) result = self.clone prop.each do |k,vals| vals.each { |v| result[k] = v } end return result end |