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, #serialize, subclasses, try, #type, type

Constructor Details

#initialize(string) ⇒ Text


18
19
20
# File 'lib/saper/items/text.rb', line 18

def initialize(string)
  @string = string
end

Class Method Details

.new(item) ⇒ Object


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

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

Instance Method Details

#==(other) ⇒ Object


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

def ==(other)
  hash == other.hash
end

#empty?Boolean


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

def empty?
  @string.empty?
end

#gsub(*args, &block) ⇒ Object


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

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

#hashObject


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

def hash
  to_s.hash
end

#split(separator, number = -1)) ⇒ Object


38
39
40
# File 'lib/saper/items/text.rb', line 38

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

#to_htmlObject


53
54
55
# File 'lib/saper/items/text.rb', line 53

def to_html
  HTML.new(self)
end

#to_jsonObject


58
59
60
# File 'lib/saper/items/text.rb', line 58

def to_json
  JSON.new(self)
end

#to_nativeObject


73
74
75
# File 'lib/saper/items/text.rb', line 73

def to_native
  @string
end

#to_sObject


68
69
70
# File 'lib/saper/items/text.rb', line 68

def to_s
  to_native
end

#to_time(format, tz = nil) ⇒ Object


63
64
65
# File 'lib/saper/items/text.rb', line 63

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

#to_xmlObject


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

def to_xml
  XML.new(self)
end