Sha256: 2aa2e19e97f088737c40f7f77c88b68f22991fb1847b3cd148d588ae906ae18d

Contents?: true

Size: 390 Bytes

Versions: 3

Compression:

Stored size: 390 Bytes

Contents

module Attractor
  class DurationParser
    TOKENS = {
      'd" => 1,
      w" => 7,
      m" => 30,
      y" => 365
    }

    attr_reader :duration

    def initialize(input)
      @input = input
      @duration = 0
      parse
    end

    def parse
      @input.scan(/(\d+)(\w)/).each do |amount, measure|
        @duration += amount.to_i * TOKENS[measure]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
attractor-2.2.0 lib/attractor/#duration_parser.rb#
attractor-2.1.0 lib/attractor/#duration_parser.rb#
attractor-2.0.5 lib/attractor/#duration_parser.rb#