Class: CLLI

Inherits:
Object
  • Object
show all
Includes:
Cities, EntityType, ISO3166, LocationType, Pattern, Validations
Defined in:
lib/clli.rb,
lib/clli/cities.rb,
lib/clli/iso3166.rb,
lib/clli/pattern.rb,
lib/clli/version.rb,
lib/clli/yaml_data.rb,
lib/clli/entity_type.rb,
lib/clli/validations.rb,
lib/clli/location_type.rb

Overview

This file defines the gem version.

Defined Under Namespace

Modules: Cities, EntityType, ISO3166, LocationType, Pattern, Validations Classes: YAMLData

Constant Summary collapse

VERSION =
'0.0.3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cities

included

Methods included from ISO3166

included

Methods included from Validations

included

Methods included from LocationType

included

Methods included from EntityType

included

Methods included from Pattern

included

Constructor Details

#initialize(str, **options) ⇒ CLLI

Create a new CLLI by parsing str.

A RuntimeError is raised if the string does not represent a valid CLLI.

Params:

str

the CLLI string to parse.

options

options which change the behavior of the parser. See CLLI::Pattern.pattern for more information.



47
48
49
# File 'lib/clli.rb', line 47

def initialize(str, **options)
  @attributes = parse(str, options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Allows the user to access attribute values as methods.



98
99
100
101
# File 'lib/clli.rb', line 98

def method_missing(method, *args)
  return @attributes[method] if @attributes.key?(method)
  super
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



36
37
38
# File 'lib/clli.rb', line 36

def attributes
  @attributes
end

Instance Method Details

#city_nameObject

Get the name of the city this CLLI is located in if known.



77
78
79
# File 'lib/clli.rb', line 77

def city_name
  self.class.city_name(place, region)
end

#country_codeObject

Get the ISO 3166 two character country code this CLLI is located in.



65
66
67
# File 'lib/clli.rb', line 65

def country_code
  self.class.iso_country(region)
end

#country_nameObject

Get the name of the country this CLLI is located in.



71
72
73
# File 'lib/clli.rb', line 71

def country_name
  self.class.country_name(region)
end

#entity_typeObject

Get a string describing the entity code for this CLLI. Note, if this is not an entity CLLI then the return value will be nil.



92
93
94
# File 'lib/clli.rb', line 92

def entity_type
  return self.class.entity_type(entity_code) if respond_to?(:entity_code)
end

#location_typeObject

Get a string describing the location code for this CLLI. Note, if this is an entity CLLI then the return value will be nil.



84
85
86
87
# File 'lib/clli.rb', line 84

def location_type
  return self.class.location_type(location_code) if respond_to?(:location_code)
  return self.class.location_type(customer_code) if respond_to?(:customer_code)
end

#respond_to?(method) ⇒ Boolean

Allows the user to check whether or not attributes exist.

Returns:

  • (Boolean)


105
106
107
108
# File 'lib/clli.rb', line 105

def respond_to?(method)
  return true if @attributes.key?(method)
  super
end

#state_codeObject

Get the ISO 3166 two character state code this CLLI is located in.



53
54
55
# File 'lib/clli.rb', line 53

def state_code
  self.class.iso_state(region)
end

#state_nameObject

Get the name of the state this CLLI is located in.



59
60
61
# File 'lib/clli.rb', line 59

def state_name
  self.class.state_name(region)
end