Class: Pinpoint::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/pinpoint/format.rb,
lib/pinpoint/format/file.rb,
lib/pinpoint/format/list.rb,
lib/pinpoint/format/style.rb,
lib/pinpoint/format/token.rb,
lib/pinpoint/format/parser.rb,
lib/pinpoint/format/tokenizer.rb,
lib/pinpoint/format/token_list.rb,
lib/pinpoint/format/parse_error.rb

Defined Under Namespace

Classes: File, List, ParseError, Parser, Style, Token, TokenList, Tokenizer, UnevenNestingError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFormat

Public: Initialize an empty Format with no styles.



10
11
12
# File 'lib/pinpoint/format.rb', line 10

def initialize
  styles = {}
end

Instance Attribute Details

#stylesObject

Returns the value of attribute styles.



5
6
7
# File 'lib/pinpoint/format.rb', line 5

def styles
  @styles
end

Class Method Details

.lookup_by_country(country) ⇒ Object

Public: Attempts to find a format for a given country.

country - A Symbol representing the lowercased two-character [ISO

3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country code for
the country you are trying to load a format for.

Example

lookup_by_country(:us)
# => <Format styles: {one_line: <Format::Style>, ....}>

Returns a Format loaded with all of the styles that it is capable of.



28
29
30
31
32
# File 'lib/pinpoint/format.rb', line 28

def self.lookup_by_country(country)
  format = new
  format.styles = Pinpoint::Format::File.styles_for(country)
  format
end

Instance Method Details

#output(address, options = {}) ⇒ Object

Public: Will output any given address for the country defined in the Format.

By default it will output in a ‘one-line’ style.

address - The address that will be formatted (typically

a Pinpoint::Address).

options - A Hash of options for the method

:style - The style to be applied to the address output
         (defaults to :one_line).

Example

output my_address, :style => :one_line
# => 'Kwik-E-Mart, 123 Apu Lane, Springfield, NW 12345, United States'

Returns a String representing the address in the specified style.



55
56
57
58
59
# File 'lib/pinpoint/format.rb', line 55

def output(address, options = {})
  requested_style = options.fetch(:style, :one_line).to_sym

  styles[requested_style].output(address)
end