lib/csl/locale.rb in csl-1.0.0.pre21 vs lib/csl/locale.rb in csl-1.0.0.pre22

- old
+ new

@@ -70,17 +70,20 @@ private attr_reader :tag_pattern end - attr_defaults :version => Schema.version, :xmlns => Schema.namespace - attr_struct :xmlns, :version + attr_defaults :version => Schema.major_version, + :xmlns => Schema.namespace - attr_children :'style-options', :info, :date, :terms + show_default_attributes! - has_language + attr_struct :xmlns, :version + attr_children :info, :'style-options', :date, :terms + has_language + attr_accessor :region alias_child :metadata, :info alias_child :dates, :date alias_child :options, :style_options @@ -163,11 +166,11 @@ attributes[:version] = version end # @return [Boolean] whether or not the Locale's version is less than CSL-Ruby's default version def legacy? - version < Schema.version + version < Schema.major_version end # @example # locale.set('en') #-> sets language to :en, region to :US # locale.set('de-AT') #-> sets language to :de, region to :AT @@ -176,22 +179,22 @@ # Sets language and region according to the passed-in locale string. If # the region part is not defined by the string, this method will set the # region to the default region for the given language. # # @raise [ArgumentError] if the argument is no valid locale string. - # A valid locale string is based on the syntax of IETF language tags; - # it consists of either a language or region tag (or both), separated - # by a hyphen. - # - # @return [self] + # A valid locale string is based on the syntax of IETF language tags; + # it consists of either a language or region tag (or both), separated + # by a hyphen. + # + # @return [self] def set(locale) @language, @region = Locale.normalize(locale).split(/-/).map(&:to_sym) self end # Sets the locale's language and region to nil. - # @return [self] + # @return [self] def clear @language, @region = nil self end @@ -236,16 +239,16 @@ # @return [String] the ordinal for the passed-in number def ordinalize(number, options = {}) raise ArgumentError, "unable to ordinalize #{number}; integer expected" unless number.respond_to?(:to_i) - number = number.to_i + number = number.to_i ordinal = terms.ordinalize number, options return number.to_s if ordinal.nil? return ordinal.to_s(options) if ordinal.long_ordinal? - + [number, ordinal.to_s(options)].join end # @example # locale.each_term { |term| block } #-> locale @@ -299,24 +302,24 @@ def valid? validate.empty? end - # @return [Locale] - def merge(*others) - deep_copy.merge!(*others) - end + # @return [Locale] + def merge(*others) + deep_copy.merge!(*others) + end - # @return [self] - def merge!(*others) - others.each do |other| - merge_options other - merge_dates other - end + # @return [self] + def merge!(*others) + others.each do |other| + merge_options other + merge_dates other + end - self - end + self + end # Locales are sorted first by language, then by region; sort order is # alphabetical with the following exceptions: the default locale is # prioritised; in case of a language match the default region of that @@ -371,25 +374,25 @@ def preamble Schema.preamble.dup end - # @param other [Locale] an other locale whose options should be merged - # @return [self] - def merge_options(other) - return self unless other.has_options? + # @param other [Locale] an other locale whose options should be merged + # @return [self] + def merge_options(other) + return self unless other.has_options? - if has_options? - options.attributes.merge! other.options.attributes - else - add_child other.options.dup - end + if has_options? + options.attributes.merge! other.options.attributes + else + add_child other.options.dup + end - self - end + self + end - # @param other [Locale] an other locale whose date nodes should be merged - # @return [self] + # @param other [Locale] an other locale whose date nodes should be merged + # @return [self] def merge_dates(other) return self unless other.has_dates? if has_dates? other.each_date do |date| \ No newline at end of file