Class: ListTool::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/list_tool/item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#textObject

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 options=nil
  "{\"text\":\"#{@text.gsub('"', '\"')}\"}"
end