Module: Pickle::Parser::Matchers

Included in:
Pickle::Parser
Defined in:
lib/pickle/parser/matchers.rb

Instance Method Summary collapse

Instance Method Details

#capture_key_and_value_in_fieldObject



82
83
84
# File 'lib/pickle/parser/matchers.rb', line 82

def capture_key_and_value_in_field
  "(?:(\\w+): #{capture_value})"
end

#capture_name_in_labelObject



78
79
80
# File 'lib/pickle/parser/matchers.rb', line 78

def capture_name_in_label
  "(?::? \"(#{match_quoted})\")"
end

#capture_number_in_ordinalObject

special capture methods



74
75
76
# File 'lib/pickle/parser/matchers.rb', line 74

def capture_number_in_ordinal
  '(?:(\d+)(?:st|nd|rd|th))'
end

#match_factoryObject



40
41
42
# File 'lib/pickle/parser/matchers.rb', line 40

def match_factory
  "(?:#{config.factories.keys.map{|n| n.gsub('_','[_ ]')}.join('|')})"
end

#match_fieldObject



28
29
30
# File 'lib/pickle/parser/matchers.rb', line 28

def match_field
  "(?:\\w+: #{match_value})"
end

#match_fieldsObject



32
33
34
# File 'lib/pickle/parser/matchers.rb', line 32

def match_fields
  "(?:#{match_field}, )*#{match_field}"
end

#match_indexObject



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

def match_index
  "(?:first|last|#{match_ordinal})"
end

#match_indexed_modelObject



48
49
50
# File 'lib/pickle/parser/matchers.rb', line 48

def match_indexed_model
  "(?:(?:#{match_index} )?#{match_factory})"
end

#match_labelObject



20
21
22
# File 'lib/pickle/parser/matchers.rb', line 20

def match_label
  "(?::? \"#{match_quoted}\")"
end

#match_labeled_modelObject



52
53
54
# File 'lib/pickle/parser/matchers.rb', line 52

def match_labeled_model
  "(?:#{match_factory}#{match_label})"
end

#match_mappingObject



36
37
38
# File 'lib/pickle/parser/matchers.rb', line 36

def match_mapping
  "(?:#{config.mappings.map(&:search).join('|')})"
end

#match_modelObject



56
57
58
# File 'lib/pickle/parser/matchers.rb', line 56

def match_model
  "(?:#{match_mapping}|#{match_prefix}?(?:#{match_indexed_model}|#{match_labeled_model}))"
end

#match_ordinalObject



4
5
6
# File 'lib/pickle/parser/matchers.rb', line 4

def match_ordinal
  '(?:\d+(?:st|nd|rd|th))'
end

#match_plural_factoryObject



44
45
46
# File 'lib/pickle/parser/matchers.rb', line 44

def match_plural_factory
  "(?:#{config.factories.keys.map{|n| n.pluralize.gsub('_','[_ ]')}.join('|')})"
end

#match_predicateObject



60
61
62
# File 'lib/pickle/parser/matchers.rb', line 60

def match_predicate
  "(?:#{config.predicates.map{|m| m.to_s.sub(/^has_/,'').sub(/\?$/,'').gsub('_','[_ ]')}.join('|')})"
end

#match_prefixObject



12
13
14
# File 'lib/pickle/parser/matchers.rb', line 12

def match_prefix
  '(?:(?:a|an|another|the|that) )'
end

#match_quotedObject



16
17
18
# File 'lib/pickle/parser/matchers.rb', line 16

def match_quoted
  '(?:\\\\"|[^\\"]|\\.)*'
end

#match_valueObject



24
25
26
# File 'lib/pickle/parser/matchers.rb', line 24

def match_value
  "(?:\"#{match_quoted}\"|nil|true|false|[+-]?[0-9_]+(?:\\.\\d+)?)"
end