Class: CSL::Locale::Term
Defined Under Namespace
Classes: Multiple, Registry, Single
Class Attribute Summary collapse
-
.form_fallbacks ⇒ Object
readonly
Returns the value of attribute form_fallbacks.
Instance Attribute Summary collapse
-
#text ⇒ Object
Returns the value of attribute text.
Attributes inherited from Node
Attributes included from Treelike
Class Method Summary collapse
Instance Method Summary collapse
- #default_ordinal? ⇒ Boolean
-
#feminine! ⇒ self?
The term with the gender attribute set to ‘feminine’, or nil if the term was already feminine.
-
#feminine? ⇒ Boolean
Whether or not the term is feminie.
- #gendered? ⇒ Boolean
- #long? ⇒ Boolean
-
#long_ordinal? ⇒ Boolean
Whether or not this term is a long-ordinal term.
-
#masculine! ⇒ self?
The term with the gender attribute set to ‘masculine’, or nil if the term was already masculine.
-
#masculine? ⇒ Boolean
Whether or not the term is masculine.
-
#match_modulo?(number) ⇒ Boolean
(also: #matches_modulo?)
This method returns whether or not the ordinal term matchs the passed-in modulus.
- #neutral? ⇒ Boolean
- #ordinal ⇒ Fixnum, ...
-
#ordinal? ⇒ Boolean
Whether or not this term is an ordinal term.
- #pluralize ⇒ Object (also: #plural)
- #set(singular, plural = nil) ⇒ Object
- #short? ⇒ Boolean
-
#short_ordinal? ⇒ Boolean
Whether or not this term is a regular ordinal term.
- #singularize ⇒ Object (also: #singular)
- #symbol? ⇒ Boolean
- #tags ⇒ Object
- #textnode? ⇒ Boolean
-
#to_s(options = nil) ⇒ String
The term as a string.
- #verb? ⇒ Boolean
- #verb_short? ⇒ Boolean
Methods inherited from Node
#<=>, #attribute?, #attributes?, #attributes_for, constantize, create, create_attributes, #custom_attributes, #deep_copy, #default_attribute?, #default_attributes, default_attributes, #each, #exact_match?, #format_page_ranges?, #formatting_options, #has_attributes?, #has_default_attributes?, #has_language?, hide_default_attributes!, hide_default_attributes?, #initialize, #initialize_copy, #inspect, #match?, match?, matches?, #merge!, #page_range_format, parse, parse!, #quotes?, #reverse_merge!, #save_to, show_default_attributes!, #strip_periods?, types
Methods included from Extensions::Nesting
Methods included from PrettyPrinter
Methods included from Treelike
#<<, #add_child, #add_children, #ancestors, #closest, #delete_child, #delete_children, #depth, #descendants, #each_ancestor, #each_child, #each_descendant, #each_sibling, #empty?, #find_child, #find_children, #has_children?, #root, #root?, #siblings, #unlink
Constructor Details
This class inherits a constructor from CSL::Node
Class Attribute Details
.form_fallbacks ⇒ Object (readonly)
Returns the value of attribute form_fallbacks.
237 238 239 |
# File 'lib/csl/locale/term.rb', line 237 def form_fallbacks @form_fallbacks end |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
223 224 225 |
# File 'lib/csl/locale/term.rb', line 223 def text @text end |
Class Method Details
.specialize(options) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/csl/locale/term.rb', line 239 def specialize() specialized = {} .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 |
Instance Method Details
#default_ordinal? ⇒ Boolean
299 300 301 |
# File 'lib/csl/locale/term.rb', line 299 def default_ordinal? attributes.name == 'ordinal' end |
#feminine! ⇒ self?
Returns the term with the gender attribute set to ‘feminine’, or nil if the term was already feminine.
385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/csl/locale/term.rb', line 385 %w{ masculine feminine }.each do |name| define_method("#{name}?") do attributes.gender.to_s == name end define_method("#{name}!") do return nil if attributes.gender.to_s == name attributes.gender = name self end end |
#feminine? ⇒ Boolean
Returns whether or not the term is feminie.
|
# File 'lib/csl/locale/term.rb', line 379
|
#gendered? ⇒ Boolean
310 311 312 |
# File 'lib/csl/locale/term.rb', line 310 def gendered? !attributes.gender.blank? end |
#long? ⇒ Boolean
334 335 336 337 |
# File 'lib/csl/locale/term.rb', line 334 def long? return true unless attribute?(:form) attributes.form.to_s =~ /^long$/i end |
#long_ordinal? ⇒ Boolean
Returns whether or not this term is a long-ordinal term.
290 291 292 |
# File 'lib/csl/locale/term.rb', line 290 def long_ordinal? /^long-ordinal(-\d\d+)?$/ === attributes.name end |
#masculine! ⇒ self?
Returns the term with the gender attribute set to ‘masculine’, or nil if the term was already masculine.
|
# File 'lib/csl/locale/term.rb', line 375
|
#masculine? ⇒ Boolean
Returns whether or not the term is masculine.
|
# File 'lib/csl/locale/term.rb', line 372
|
#match_modulo?(number) ⇒ Boolean Also known as: matches_modulo?
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.
268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# 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 |
#neutral? ⇒ Boolean
314 315 316 |
# File 'lib/csl/locale/term.rb', line 314 def neutral? !gendered? end |
#ordinal ⇒ Fixnum, ...
304 305 306 307 308 |
# 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 |
#ordinal? ⇒ Boolean
Returns whether or not this term is an ordinal term.
285 286 287 |
# File 'lib/csl/locale/term.rb', line 285 def ordinal? /^(long-)?ordinal(-\d\d+)?$/ === attributes.name end |
#pluralize ⇒ Object Also known as: plural
350 351 352 353 |
# File 'lib/csl/locale/term.rb', line 350 def pluralize return text if textnode? children.multiple.to_s end |
#set(singular, plural = nil) ⇒ Object
360 361 362 363 364 365 366 367 368 369 |
# 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 |
#short? ⇒ Boolean
318 319 320 |
# File 'lib/csl/locale/term.rb', line 318 def short? attribute?(:form) && attributes.form.to_s =~ /^short$/i end |
#short_ordinal? ⇒ Boolean
Returns whether or not this term is a regular ordinal term.
295 296 297 |
# File 'lib/csl/locale/term.rb', line 295 def short_ordinal? /^ordinal(-\d\d+)?$/ === attributes.name end |
#singularize ⇒ Object Also known as: singular
343 344 345 346 |
# File 'lib/csl/locale/term.rb', line 343 def singularize return text if textnode? children.single.to_s end |
#symbol? ⇒ Boolean
330 331 332 |
# File 'lib/csl/locale/term.rb', line 330 def symbol? attribute?(:form) && attributes.form.to_s =~ /^symbol$/i end |
#tags ⇒ Object
397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/csl/locale/term.rb', line 397 def if textnode? [ "<#{[nodename, *attribute_assignments].join(' ')}>", CSL.encode_xml_text(text), "</#{nodename}>" ] else super end end |
#textnode? ⇒ Boolean
339 340 341 |
# File 'lib/csl/locale/term.rb', line 339 def textnode? !text.blank? end |
#to_s(options = nil) ⇒ String
Returns the term as a string.
418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/csl/locale/term.rb', line 418 def to_s( = nil) if textnode? text else if pluralize?() pluralize else singularize end end end |
#verb? ⇒ Boolean
322 323 324 |
# File 'lib/csl/locale/term.rb', line 322 def verb? attribute?(:form) && attributes.form.to_s =~ /^verb$/i end |
#verb_short? ⇒ Boolean
326 327 328 |
# File 'lib/csl/locale/term.rb', line 326 def verb_short? attribute?(:form) && attributes.form.to_s =~ /^verb-short$/i end |