class CSL::Locale::Term
Attributes
Public Class Methods
Source
# File lib/csl/locale/term.rb, line 239 def specialize(options) specialized = {} options.each do |key, value| key = key.to_sym if !value.nil? && Term::Attributes.keys.include?(key) specialized[key] = value end end specialized.delete :'gender-form' unless specialized[:'gender-form'].to_s =~ /^masculine|feminine$/ specialized end
Public Instance Methods
Source
# File lib/csl/locale/term.rb, line 299 def default_ordinal? attributes.name == 'ordinal' end
Source
# File lib/csl/locale/term.rb, line 310 def gendered? !attributes.gender.blank? end
Source
# File lib/csl/locale/term.rb, line 334 def long? return true unless attribute?(:form) attributes.form.to_s =~ /^long$/i end
Source
# File lib/csl/locale/term.rb, line 290 def long_ordinal? /^long-ordinal(-\d\d+)?$/ === attributes.name end
@return [Boolean] whether or not this term is a long-ordinal term
Source
# File lib/csl/locale/term.rb, line 268 def match_modulo?(number) return false unless ordinal? case attributes.match when 'last-two-digits' ordinal == number % 100 when 'last-digit' ordinal == number % 10 when 'whole-number' ordinal == number else true end end
This method returns whether or not the ordinal term matchs the passed-in modulus. This is determined by the ordinal term’s match attribute: a value of ‘last-two-digits’ matches a modulus of 100, ‘last-digit’ matches a modulus of 10 and ‘whole-number’ matches only if the number is identical to the ordinal value.
If the term is no ordinal term, this methods always returns false.
@return [Boolean] whether or not the ordinal term matches the
passed-in number.
Source
# File lib/csl/locale/term.rb, line 304 def ordinal return unless ordinal? return :default if attributes.name == 'ordinal' attributes.name[/\d+/].to_i end
@return [Fixnum, :default, nil]
Source
# File lib/csl/locale/term.rb, line 285 def ordinal? /^(long-)?ordinal(-\d\d+)?$/ === attributes.name end
@return [Boolean] whether or not this term is an ordinal term
Source
# File lib/csl/locale/term.rb, line 350 def pluralize return text if textnode? children.multiple.to_s end
Source
# File lib/csl/locale/term.rb, line 360 def set(singular, plural = nil) if plural.nil? self.text = singular else self.single = singular self.multiple = plural end self end
Source
# File lib/csl/locale/term.rb, line 318 def short? attribute?(:form) && attributes.form.to_s =~ /^short$/i end
Source
# File lib/csl/locale/term.rb, line 295 def short_ordinal? /^ordinal(-\d\d+)?$/ === attributes.name end
@return [Boolean] whether or not this term is a regular ordinal term
Source
# File lib/csl/locale/term.rb, line 343 def singularize return text if textnode? children.single.to_s end
Source
# File lib/csl/locale/term.rb, line 330 def symbol? attribute?(:form) && attributes.form.to_s =~ /^symbol$/i end
Source
# File lib/csl/locale/term.rb, line 418 def to_s(options = nil) if textnode? text else if pluralize?(options) pluralize else singularize end end end
@param options [Hash,nil] an optional configuration hash
@option options [:singular,:plural] :number (:singular) whether to
return the term's singular or plural variant.
@option options [Boolean] :plural (false) whether or not to return
the term's plural variant (this option, if set, takes precedence over :number).
@return [String] the term as a string
Source
# File lib/csl/locale/term.rb, line 322 def verb? attribute?(:form) && attributes.form.to_s =~ /^verb$/i end
Source
# File lib/csl/locale/term.rb, line 326 def verb_short? attribute?(:form) && attributes.form.to_s =~ /^verb-short$/i end
Private Instance Methods
Source
# File lib/csl/locale/term.rb, line 435 def pluralize?(options) return false if options.nil? case when options.key?(:plural) || options.key?('plural') options[:plural] || options['plural'] when options.key?(:number) || options.key?('number') key = options[:number] || options['number'] if key.is_a?(Integer) || key.to_s =~ /^[+-]?\d+$/ key.to_i > 1 else !key.blank? && key.to_s =~ /^plural/i end else false end end