Module: Pickle::Parser::Matchers
- Included in:
- Pickle::Parser
- Defined in:
- lib/pickle/parser/matchers.rb
Instance Method Summary collapse
- #capture_key_and_value_in_field ⇒ Object
- #capture_models_in_collection ⇒ Object
- #capture_name_in_label ⇒ Object
-
#capture_number_in_ordinal ⇒ Object
special capture methods.
- #match_collection ⇒ Object
- #match_factory ⇒ Object
- #match_field ⇒ Object
- #match_fields ⇒ Object
- #match_index ⇒ Object
- #match_indexed_model ⇒ Object
- #match_label ⇒ Object
- #match_labeled_model ⇒ Object
- #match_mapping ⇒ Object
- #match_model ⇒ Object
- #match_ordinal ⇒ Object
- #match_plural_factory ⇒ Object
- #match_predicate ⇒ Object
- #match_prefix ⇒ Object
- #match_quoted ⇒ Object
- #match_value ⇒ Object
Instance Method Details
#capture_key_and_value_in_field ⇒ Object
86 87 88 |
# File 'lib/pickle/parser/matchers.rb', line 86 def capture_key_and_value_in_field "(?:(\\w+): #{capture_value})" end |
#capture_models_in_collection ⇒ Object
90 91 92 |
# File 'lib/pickle/parser/matchers.rb', line 90 def capture_models_in_collection "(?:\\[(?:(#{match_model}), )*(#{match_model})\\])" end |
#capture_name_in_label ⇒ Object
82 83 84 |
# File 'lib/pickle/parser/matchers.rb', line 82 def capture_name_in_label "(?::? \"(#{match_quoted})\")" end |
#capture_number_in_ordinal ⇒ Object
special capture methods
78 79 80 |
# File 'lib/pickle/parser/matchers.rb', line 78 def capture_number_in_ordinal '(?:(\d+)(?:st|nd|rd|th))' end |
#match_collection ⇒ Object
20 21 22 |
# File 'lib/pickle/parser/matchers.rb', line 20 def match_collection "(?:\\[(?:#{match_model}, )*#{match_model}\\])" end |
#match_factory ⇒ Object
44 45 46 |
# File 'lib/pickle/parser/matchers.rb', line 44 def match_factory "(?:#{config.factories.keys.map{|n| n.gsub('_','[_ ]')}.join('|')})" end |
#match_field ⇒ Object
32 33 34 |
# File 'lib/pickle/parser/matchers.rb', line 32 def match_field "(?:\\w+: #{match_value})" end |
#match_fields ⇒ Object
36 37 38 |
# File 'lib/pickle/parser/matchers.rb', line 36 def match_fields "(?:#{match_field}, )*#{match_field}" end |
#match_index ⇒ Object
8 9 10 |
# File 'lib/pickle/parser/matchers.rb', line 8 def match_index "(?:first|last|#{match_ordinal})" end |
#match_indexed_model ⇒ Object
52 53 54 |
# File 'lib/pickle/parser/matchers.rb', line 52 def match_indexed_model "(?:(?:#{match_index} )?#{match_factory})" end |
#match_label ⇒ Object
24 25 26 |
# File 'lib/pickle/parser/matchers.rb', line 24 def match_label "(?::? \"#{match_quoted}\")" end |
#match_labeled_model ⇒ Object
56 57 58 |
# File 'lib/pickle/parser/matchers.rb', line 56 def match_labeled_model "(?:#{match_factory}#{match_label})" end |
#match_mapping ⇒ Object
40 41 42 |
# File 'lib/pickle/parser/matchers.rb', line 40 def match_mapping "(?:#{config.mappings.map(&:search).join('|')})" end |
#match_model ⇒ Object
60 61 62 |
# File 'lib/pickle/parser/matchers.rb', line 60 def match_model "(?:#{match_mapping}|#{match_prefix}?(?:#{match_indexed_model}|#{match_labeled_model}))" end |
#match_ordinal ⇒ Object
4 5 6 |
# File 'lib/pickle/parser/matchers.rb', line 4 def match_ordinal '(?:\d+(?:st|nd|rd|th))' end |
#match_plural_factory ⇒ Object
48 49 50 |
# File 'lib/pickle/parser/matchers.rb', line 48 def match_plural_factory "(?:#{config.factories.keys.map{|n| n.pluralize.gsub('_','[_ ]')}.join('|')})" end |
#match_predicate ⇒ Object
64 65 66 |
# File 'lib/pickle/parser/matchers.rb', line 64 def match_predicate "(?:#{config.predicates.map{|m| m.to_s.sub(/^has_/,'').sub(/\?$/,'').gsub('_','[_ ]')}.join('|')})" end |
#match_prefix ⇒ Object
12 13 14 |
# File 'lib/pickle/parser/matchers.rb', line 12 def match_prefix '(?:(?:a|an|another|the|that) )' end |
#match_quoted ⇒ Object
16 17 18 |
# File 'lib/pickle/parser/matchers.rb', line 16 def match_quoted '(?:[^\\"]|\\.)*' end |
#match_value ⇒ Object
28 29 30 |
# File 'lib/pickle/parser/matchers.rb', line 28 def match_value "(?:\"#{match_quoted}\"|#{match_collection}|nil|true|false|[+-]?\\d+(?:\\.\\d+)?)" end |