instance method
friendly_identifier
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
friendly_identifier(skip_first_part = false)
Returns a friendlier version of the identifier. Set skip_first_part to omit the first part of the identifier (typically a region name) where there is more than one part.
For example:
Timezone.get('Europe/Paris').friendly_identifier(false) #=> "Europe - Paris" Timezone.get('Europe/Paris').friendly_identifier(true) #=> "Paris" Timezone.get('America/Indiana/Knox').friendly_identifier(false) #=> "America - Knox, Indiana" Timezone.get('America/Indiana/Knox').friendly_identifier(true) #=> "Knox, Indiana"
Parameters
-
skip_first_partopt = false
Source
# File activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb, line 249
def friendly_identifier(skip_first_part = false)
parts = identifier.split('/')
if parts.empty?
# shouldn't happen
identifier
elsif parts.length == 1
parts[0]
else
if skip_first_part
result = ''
else
result = parts[0] + ' - '
end
parts[1, parts.length - 1].reverse_each {|part|
part.gsub!(/_/, ' ')
if part.index(/[a-z]/)
# Missing a space if a lower case followed by an upper case and the
# name isn't McXxxx.
part.gsub!(/([^M][a-z])([A-Z])/, '\1 \2')
part.gsub!(/([M][a-bd-z])([A-Z])/, '\1 \2')
# Missing an apostrophe if two consecutive upper case characters.
part.gsub!(/([A-Z])([A-Z])/, '\1\'\2')
end
result << part
result << ', '
}
result.slice!(result.length - 2, 2)
result
end
end
Defined in activesupport/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb line 249
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in TZInfo::Timezone