Sha256: b46a322f0678ae94dc092c73f496f20e55d36d4ef8872d175091a29d66188956

Contents?: true

Size: 956 Bytes

Versions: 2

Compression:

Stored size: 956 Bytes

Contents

grammar Timeparsing

  rule root
    (times / whitespace)*
    {
      def value
        elements.inject(0) do |akk, e|
          akk += e.value
          akk
        end
      end
    }
  end

  rule times
    dot_seperated / hours / minutes / other_stuff
    {
      def value
        elements.inject(0) do |akk, e|
          akk += e.value
          akk
        end
      end
    }
  end

  rule dot_seperated
    (([0-9]* ':' [0-9]*) / (hours ':' minutes))
    {
      def value
        elements[0].text_value.to_i*60 + elements[2].text_value.to_i
      end
    }
  end

  rule hours
    [0-9]+ ('hours' / 'hrs' / 'h')
    {
      def value
        self.text_value.to_i * 60
      end
    }
  end

  rule minutes
    [0-9]+ ("minutes" / "min" /  "m")
    {
      def value
        self.text_value.to_i
      end
    }
  end

  rule whitespace
    " "
    { def value; 0; end }
  end

  rule other_stuff
    [a-zA-Z]+
    { def value; 0; end }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timeparser-0.0.3 lib/timeparser/timeparsing.treetop
timeparser-0.0.2 lib/timeparser/timeparsing.treetop