Class: RelatonBib::Place::RegionType

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bib/place.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, iso: nil, recommended: nil) ⇒ RegionType

Initialize region type.

Parameters:

  • name (String)

    name of region

  • iso (String, nil) (defaults to: nil)

    ISO code of region

  • recommended (Boolean, nil) (defaults to: nil)

    recommended region



95
96
97
98
99
# File 'lib/relaton_bib/place.rb', line 95

def initialize(name:, iso: nil, recommended: nil)
  @name = name
  @iso  = iso
  @recommended = recommended
end

Instance Attribute Details

#isoStrign? (readonly)

Returns ISO code of region.

Returns:

  • (Strign, nil)

    ISO code of region



83
84
85
# File 'lib/relaton_bib/place.rb', line 83

def iso
  @iso
end

#nameStrign (readonly)

Returns name of region.

Returns:

  • (Strign)

    name of region



80
81
82
# File 'lib/relaton_bib/place.rb', line 80

def name
  @name
end

Returns <description>.

Returns:

  • (Boolean, nil)

    <description>



86
87
88
# File 'lib/relaton_bib/place.rb', line 86

def recommended
  @recommended
end

Instance Method Details

#to_asciibib(pref, count = 1) ⇒ String

Render region type as AsciiBib.

Parameters:

  • pref (String)

    prefix

  • count (Integer) (defaults to: 1)

    number of region types

Returns:

  • (String)

    region type as AsciiBib



132
133
134
135
136
137
138
# File 'lib/relaton_bib/place.rb', line 132

def to_asciibib(pref, count = 1) # rubocop:disable Metrics/AbcSize
  out = count > 1 ? "#{pref}::\n" : ""
  out += "#{pref}.name:: #{name}\n"
  out += "#{pref}.iso:: #{iso}\n" if iso
  out += "#{pref}.recommended:: #{recommended}\n" if recommended
  out
end

#to_hashHash

Render region type as Hash.

Returns:

  • (Hash)

    region type as Hash



117
118
119
120
121
122
# File 'lib/relaton_bib/place.rb', line 117

def to_hash
  hash = { "name" => name }
  hash["iso"] = iso if iso
  hash["recommended"] = recommended unless recommended.nil?
  hash
end

#to_xml(builder) ⇒ Object

Render region type as XML.

Parameters:

  • builder (Nokogiri::XML::Builder)

    XML builder



106
107
108
109
110
# File 'lib/relaton_bib/place.rb', line 106

def to_xml(builder)
  builder.parent["iso"] = iso if iso
  builder.parent["recommended"] = recommended.to_s unless recommended.nil?
  builder.text name
end