Class: Humanized::Parser::Result
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#original_string ⇒ Object
readonly
Returns the value of attribute original_string.
-
#parsed_string ⇒ Object
readonly
Returns the value of attribute parsed_string.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #call ⇒ Object
- #emit(value, parsed_or_options = nil) ⇒ Object
- #failure ⇒ Object
-
#initialize(str, options = {}, &block) ⇒ Result
constructor
A new instance of Result.
- #success? ⇒ Boolean
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, ={}, &block) s = str.dup.freeze @original_string = s @parsed_string = s @options = @success = false if block instance_eval &block end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/more/humanized/parser.rb', line 23 def @options end |
#original_string ⇒ Object (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_string ⇒ Object (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 |
#success ⇒ Object (readonly)
Returns the value of attribute success.
23 24 25 |
# File 'lib/more/humanized/parser.rb', line 23 def success @success end |
#value ⇒ Object (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
#call ⇒ Object
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, = nil) @value = value @success = true if .kind_of? String @parsed_string = parsed.dup.freeze elsif .kind_of? Hash @options.update end return self end |
#failure ⇒ Object
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
29 30 31 |
# File 'lib/more/humanized/parser.rb', line 29 def success? @success end |