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

TODO:

Returns a new instance of Text


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

def initialize(string)
  @string = string
end

Class Method Details

.new(item) ⇒ Object

TODO:

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

TODO:

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

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

#empty?Boolean

TODO:

Returns:

  • (Boolean)

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

def empty?
  @string.empty?
end

#gsub(*args, &block) ⇒ Object

TODO:

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

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

#hashObject

TODO:

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

def hash
  to_s.hash
end

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

TODO:

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

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

#to_htmlObject

TODO:

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

def to_html
  HTML.new(self)
end

#to_jsonObject

TODO:

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

def to_json
  JSON.new(self)
end

#to_nativeObject

TODO:

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

def to_native
  @string
end

#to_sObject

TODO:

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

def to_s
  to_native
end

#to_time(format, tz = nil) ⇒ Object

TODO:

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

TODO:

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

def to_xml
  XML.new(self)
end