Sha256: 94d7cb599ad56e6e3d909d2e26009f1b01d4ed81dec1ee4c74fc784b881fd7eb

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

module PicturehouseUk
  # @api private
  module Internal
    module Parser
      # Parses a chunk of HTML to derive address
      class Address
        # @param [String] node the HTML to parse into an address
        # @return [PicturehouseUk::Internal::AddressParser]
        def initialize(html)
          @html = html.to_s
        end

        # @return [Hash] contains :street_address, :extended_address, :locality,
        # :postal_code, :country
        # @note Uses the address naming from http://microformats.org/wiki/adr
        def address
          {
            street_address:   array[1],
            extended_address: array.length > 5 ? array[2] : nil,
            locality:         town,
            region:           array[-2] == town ? nil : array[-2],
            postal_code:      array[-1],
            country:          'United Kingdom'
          }
        end

        private

        def town
          @town ||= array[0].to_s.split(', ')[-1]
        end

        def array
          @array ||= Array(@html.gsub(/\<.?p.?\>/, '').split('<br>'))
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
picturehouse_uk-3.0.14 lib/picturehouse_uk/internal/parser/address.rb
picturehouse_uk-3.0.13 lib/picturehouse_uk/internal/parser/address.rb
picturehouse_uk-3.0.12 lib/picturehouse_uk/internal/parser/address.rb
picturehouse_uk-3.0.11 lib/picturehouse_uk/internal/parser/address.rb
picturehouse_uk-3.0.10 lib/picturehouse_uk/internal/parser/address.rb
picturehouse_uk-3.0.9 lib/picturehouse_uk/internal/parser/address.rb
picturehouse_uk-3.0.8 lib/picturehouse_uk/internal/parser/address.rb
picturehouse_uk-3.0.7 lib/picturehouse_uk/internal/parser/address.rb