Class: Parsable::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/parsable/parser.rb

Constant Summary collapse

REGEX =
/\{{2}(\w*\.?\S[^\{\{]*?)\}{2}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Parser

Returns a new instance of Parser.



8
9
10
# File 'lib/parsable/parser.rb', line 8

def initialize args={}
  @original_string = args.fetch(:string).to_s
end

Instance Attribute Details

#original_stringObject

Returns the value of attribute original_string.



6
7
8
# File 'lib/parsable/parser.rb', line 6

def original_string
  @original_string
end

#strings=(value) ⇒ Object

Sets the attribute strings

Parameters:

  • value

    the value to set the attribute strings to.



6
7
8
# File 'lib/parsable/parser.rb', line 6

def strings=(value)
  @strings = value
end

Instance Method Details

#parseObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/parsable/parser.rb', line 12

def parse
  strings.map do |string|
    object, attribute = capture(string)

    Parsable::ParsedItem.new(\
      :original  => string,
      :object    => object,
      :attribute => attribute
    )
  end
end