Sha256: d3a8e40dea01d8071c3045a84ebacf8bb6e6cda1e88c98f8e778da507632e5eb

Contents?: true

Size: 496 Bytes

Versions: 2

Compression:

Stored size: 496 Bytes

Contents

# encoding: UTF-8

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}.+[a-zA-Z]{2}\d{3}-\d{4})')
    end

    private

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

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
parse_p1-0.1.0 lib/parse_p1/base.rb
parse_p1-0.0.9 lib/parse_p1/base.rb