Class: Saper::Items::Text

Inherits:
Saper::Item show all
Defined in:
lib/saper/items/text.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Saper::Item

#==, [], exists?, inherited, subclasses, try, type, #type

Constructor Details

#initialize(string) ⇒ Text

Returns a new instance of Text.



16
17
18
# File 'lib/saper/items/text.rb', line 16

def initialize(string)
  @string = string
end

Class Method Details

.new(item) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/saper/items/text.rb', line 5

def self.new(item)
  super case item
  when String
    item
  when Text
    item.to_s
  else
    raise(InvalidItem, item)
  end
end

Instance Method Details

#gsub(*args, &block) ⇒ Object



24
25
26
# File 'lib/saper/items/text.rb', line 24

def gsub(*args, &block)
  @string.gsub(*args, &block)
end

#split(separator, number = nil) ⇒ Object



20
21
22
# File 'lib/saper/items/text.rb', line 20

def split(separator, number = nil)
  @string.split(separator, number)
end

#to_htmlObject



32
33
34
# File 'lib/saper/items/text.rb', line 32

def to_html
  HTML.new(self)
end

#to_jsonObject



36
37
38
# File 'lib/saper/items/text.rb', line 36

def to_json
  JSON.new(self)
end

#to_nativeObject



48
49
50
# File 'lib/saper/items/text.rb', line 48

def to_native
  to_s
end

#to_sObject



44
45
46
# File 'lib/saper/items/text.rb', line 44

def to_s
  @string
end

#to_time(format, tz = nil) ⇒ Object



40
41
42
# File 'lib/saper/items/text.rb', line 40

def to_time(format, tz = nil)
  Time.new(self, format, tz)
end

#to_xmlObject



28
29
30
# File 'lib/saper/items/text.rb', line 28

def to_xml
  XML.new(self)
end