Class: Artificial::Parsers::StringParser

Inherits:
Object
  • Object
show all
Defined in:
lib/artificial/parsers/string_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ StringParser

Returns a new instance of StringParser.



8
9
10
11
# File 'lib/artificial/parsers/string_parser.rb', line 8

def initialize(input)
  @input = input
  @parsed_data = {}
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



6
7
8
# File 'lib/artificial/parsers/string_parser.rb', line 6

def input
  @input
end

#parsed_dataObject (readonly)

Returns the value of attribute parsed_data.



6
7
8
# File 'lib/artificial/parsers/string_parser.rb', line 6

def parsed_data
  @parsed_data
end

Instance Method Details

#parseObject



13
14
15
16
17
18
19
20
# File 'lib/artificial/parsers/string_parser.rb', line 13

def parse
  @parsed_data = {
    text: @input,
    format: 'string',
    type: 'simple_text'
  }
  self
end

#to_hashObject



26
27
28
# File 'lib/artificial/parsers/string_parser.rb', line 26

def to_hash
  @parsed_data
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/artificial/parsers/string_parser.rb', line 22

def valid?
  @input.is_a?(String) && !@input.empty?
end