Sha256: 1de6cc59d84acfd53841cc01b3275edcde4903729fbb2504c4b0c9f4812726bf

Contents?: true

Size: 459 Bytes

Versions: 3

Compression:

Stored size: 459 Bytes

Contents

module ParseP1

  class Base

    include ParseP1::Electricity
    include ParseP1::Gas

    attr_reader :data

    def initialize(data)
      @data = data
    end

    def valid?
      !data.match(/!$/).nil? && !device_id.nil?
    end

    def device_id
      match_within_one_p1_record('\/([a-zA-Z]{3}\d{1}.+)\r$')
    end

    private

    def match_within_one_p1_record(pattern)
      data.match(/[\W|\w]*#{pattern}[\W|\w]*!/)
      $1
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
parse_p1-0.0.6 lib/parse_p1/base.rb
parse_p1-0.0.5 lib/parse_p1/base.rb
parse_p1-0.0.4 lib/parse_p1/base.rb