Class: Humanized::Parser::Result

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

Direct Known Subclasses

ParserMissing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str, options = {}, &block) ⇒ Result

Returns a new instance of Result.



55
56
57
58
59
60
61
62
63
64
# File 'lib/more/humanized/parser.rb', line 55

def initialize(str, options ={}, &block)
  s = str.dup.freeze
  @original_string = s
  @parsed_string = s
  @options = options
  @success = false
  if block
    instance_eval &block
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/more/humanized/parser.rb', line 23

def options
  @options
end

#original_stringObject (readonly)

Returns the value of attribute original_string.



23
24
25
# File 'lib/more/humanized/parser.rb', line 23

def original_string
  @original_string
end

#parsed_stringObject (readonly)

Returns the value of attribute parsed_string.



23
24
25
# File 'lib/more/humanized/parser.rb', line 23

def parsed_string
  @parsed_string
end

#successObject (readonly)

Returns the value of attribute success.



23
24
25
# File 'lib/more/humanized/parser.rb', line 23

def success
  @success
end

#valueObject (readonly)

Returns the value of attribute value.



23
24
25
# File 'lib/more/humanized/parser.rb', line 23

def value
  @value
end

Instance Method Details

#callObject



33
34
35
36
37
# File 'lib/more/humanized/parser.rb', line 33

def call
  if success?
    yield @value
  end
end

#emit(value, parsed_or_options = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/more/humanized/parser.rb', line 66

def emit(value, parsed_or_options = nil)
  @value = value
  @success = true
  if parsed_or_options.kind_of? String
    @parsed_string = parsed.dup.freeze
  elsif parsed_or_options.kind_of? Hash
    @options.update parsed_or_options
  end
  return self
end

#failureObject



47
48
49
50
51
52
53
# File 'lib/more/humanized/parser.rb', line 47

def failure
  if block_given?
    yield() unless success?
    return self
  end
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/more/humanized/parser.rb', line 29

def success?
  @success
end