Class: ListTool::Item
- Inherits:
-
Object
- Object
- ListTool::Item
- Defined in:
- lib/list_tool/item.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(arg) ⇒ Item
constructor
A new instance of Item.
- #to_json(options = nil) ⇒ Object
Constructor Details
#initialize(arg) ⇒ Item
Returns a new instance of Item.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/list_tool/item.rb', line 6 def initialize arg if arg.is_a?(String) @text = arg elsif arg.is_a?(Hash) raise(ArgumentError, "item text not found in given hash") unless arg['text'].is_a?(String) @text = arg["text"] else raise(ArgumentError, "argument expected to be Hash or String, #{arg.class} given") end end |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
4 5 6 |
# File 'lib/list_tool/item.rb', line 4 def text @text end |
Instance Method Details
#to_json(options = nil) ⇒ Object
17 18 19 |
# File 'lib/list_tool/item.rb', line 17 def to_json =nil "{\"text\":\"#{@text.gsub('"', '\"')}\"}" end |