Class: Microkit::Item
- Inherits:
-
Object
- Object
- Microkit::Item
- Defined in:
- lib/microkit/item.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#change ⇒ Object
readonly
Returns the value of attribute change.
Instance Method Summary collapse
- #get_item_value(item) ⇒ Object
-
#initialize(value, name) ⇒ Item
constructor
A new instance of Item.
- #update(value) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(value, name) ⇒ Item
Returns a new instance of Item.
6 7 8 9 10 |
# File 'lib/microkit/item.rb', line 6 def initialize(value, name) @change = Publisher.new @item = value @name = name end |
Instance Attribute Details
#change ⇒ Object (readonly)
Returns the value of attribute change.
5 6 7 |
# File 'lib/microkit/item.rb', line 5 def change @change end |
Instance Method Details
#get_item_value(item) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/microkit/item.rb', line 25 def get_item_value(item) case item["type"] when "string" return item["value"].to_s when "number" return item["value"].to_f when "boolean" return item["value"] == true || item["value"] == "true" end end |
#update(value) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/microkit/item.rb', line 16 def update(value) prev_value = self.value have_been_changed = @item["value"] != value["value"] or @item["type"] != value["type"] @item = value if have_been_changed then @change.publish(self.value, prev_value) end end |
#value ⇒ Object
12 13 14 |
# File 'lib/microkit/item.rb', line 12 def value self.get_item_value @item end |