Module: Barometer::Support::Matchers::Formats

Included in:
HaveData, HaveForecast
Defined in:
lib/barometer/support/matchers/formats.rb

Instance Method Summary collapse

Instance Method Details

#_find_regex(format) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/barometer/support/matchers/formats.rb', line 11

def _find_regex(format)
  case format
  when :time
    /^\d{1,4}-\d{1,2}-\d{1,2} \d{2}:\d{2}:\d{2} [\-\+\d]{5}$/i
  when :optional_string
    /^[\w \.-]*$/i
  when :string
    /^[\w \.,-]{2,}$/i
  when :number
    /^\d{1,3}$/i
  when :float
    /^[\d\.]{1,5}$/i
  when :temperature
    /^-?[0-9\.]{1,20}[ ]?[cfCF]?$/i
  when :pressure
    /^[0-9\.]{1,20}[ ]?[a-zA-Z]{0,3}$/i
  when :vector
    /^[0-9\.]{1,20} (?:mph|kph) (?:[nesw]{1,3}(?:orth|outh|t|ast)?|@ [0-9\.]{1,5} degrees)$/i
  when :distance
    /^[0-9\.]{1,20}[ ]?k?m?$/i
  when Regexp
    format
  end
end

#is_of_format?(format, value) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/barometer/support/matchers/formats.rb', line 7

def is_of_format?(format, value)
  value.match(_find_regex(format))
end