Class: TwitterCldr::Transforms::TransformId

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_cldr/transforms/transform_id.rb

Constant Summary collapse

CHAIN =
[
  :normal_fallback1, :normal_fallback2, :laddered_fallback1,
  :normal_fallback3, :laddered_fallback2
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, target, variant = nil) ⇒ TransformId

Returns a new instance of TransformId.



140
141
142
143
144
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 140

def initialize(source, target, variant = nil)
  @source = source
  @target = target
  @variant = variant
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



138
139
140
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 138

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



138
139
140
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 138

def target
  @target
end

#variantObject (readonly)

Returns the value of attribute variant.



138
139
140
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 138

def variant
  @variant
end

Class Method Details

.find(source_locale_or_str, target_locale_or_str) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 18

def find(source_locale_or_str, target_locale_or_str)
  source_locale = parse_locale(source_locale_or_str)
  target_locale = parse_locale(target_locale_or_str)
  source_chain = map_chain_for(source_locale)
  target_chain = map_chain_for(target_locale)
  variants = variants_for(source_locale, target_locale)

  # add original locale strings to chain in case they aren't actually
  # locales (think 'hiragana', etc)
  source_chain << [source_locale_or_str.to_s]
  target_chain << [target_locale_or_str.to_s]

  find_in_chains(
    source_chain, target_chain, variants
  )
end

.join(source, target, variant = nil) ⇒ Object



48
49
50
51
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 48

def join(source, target, variant = nil)
  base = "#{source}-#{target}"
  variant ? "#{base}/#{variant}" : base
end

.join_file_name(parts) ⇒ Object



53
54
55
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 53

def join_file_name(parts)
  parts.compact.join('-')
end

.parse(str) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 35

def parse(str)
  if normalized = normalize(str)
    new(*split(normalized))
  else
    raise InvalidTransformIdError,
      "'#{str}' is not a valid transform id"
  end
end

.split(str) ⇒ Object



44
45
46
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 44

def split(str)
  str.split(/[\-\/]/)
end

Instance Method Details

#file_nameObject



154
155
156
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 154

def file_name
  self.class.join_file_name([source, target, variant])
end

#has_variant?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 146

def has_variant?
  !!variant
end

#reverseObject



150
151
152
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 150

def reverse
  self.class.new(target, source, variant)
end

#to_sObject



158
159
160
# File 'lib/twitter_cldr/transforms/transform_id.rb', line 158

def to_s
  self.class.join(source, target, variant)
end