Sha256: f49935bd39eb4d6f886b9b7c8f5ba02c81603b0b5314c8af580800f7f672f18f

Contents?: true

Size: 837 Bytes

Versions: 12

Compression:

Stored size: 837 Bytes

Contents

module Fandango
  class Parser::Theater

    def initialize(entry)
      @entry = entry
    end

    # Compose hash with each attribute as key and result of #parse_<attribute> as value.
    def parse
      atts = [:name, :id, :address, :postal_code]
      atts.each_with_object({}) do |attr, hash|
        hash[attr] = send :"parse_#{attr}"
      end
    end

    private

    def parse_name
      @entry[:title]
    end

    # E.g. 'aaicu' in http://www.fandango.com/northpark7_aaicu/theaterpage
    def parse_id
      @entry[:url].match(%r{fandango\.com/.*_(?<id>.*)/theaterpage})[:id]
    end

    # Cache address in variable for postal_code.
    def parse_address
      @address = @entry.summary_doc.at_css('p').content
    end

    def parse_postal_code
      @address.match(/(?<postal_code>\d+)$/)[:postal_code]
    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fandango-0.2.1 lib/fandango/parsers/theater.rb
fandango-0.2.0 lib/fandango/parsers/theater.rb
fandango-0.1.9 lib/fandango/parsers/theater.rb
fandango-0.1.8 lib/fandango/parsers/theater.rb
fandango-0.1.7 lib/fandango/parsers/theater.rb
fandango-0.1.6 lib/fandango/parsers/theater.rb
fandango-0.1.5 lib/fandango/parsers/theater.rb
fandango-0.1.4 lib/fandango/parsers/theater.rb
fandango-0.1.3 lib/fandango/parsers/theater.rb
fandango-0.1.2 lib/fandango/parsers/theater.rb
fandango-0.1.1 lib/fandango/parsers/theater.rb
fandango-0.1.0 lib/fandango/parsers/theater.rb