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)
- #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?, #formatting_options, #has_attributes?, #has_default_attributes?, #has_language?, hide_default_attributes!, hide_default_attributes?, #initialize, #initialize_copy, #inspect, #match?, match?, matches?, parse, parse!, #save_to, show_default_attributes!, types
Methods included from PrettyPrinter
Methods included from Treelike
#<<, #add_child, #add_children, #ancestors, #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.
213 214 215 |
# File 'lib/csl/locale/term.rb', line 213 def form_fallbacks @form_fallbacks end |
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
199 200 201 |
# File 'lib/csl/locale/term.rb', line 199 def text @text end |
Class Method Details
.specialize(options) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/csl/locale/term.rb', line 215 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
275 276 277 |
# File 'lib/csl/locale/term.rb', line 275 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.
346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/csl/locale/term.rb', line 346 %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 340
|
#gendered? ⇒ Boolean
286 287 288 |
# File 'lib/csl/locale/term.rb', line 286 def gendered? !attributes.gender.blank? end |
#long? ⇒ Boolean
310 311 312 313 |
# File 'lib/csl/locale/term.rb', line 310 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.
266 267 268 |
# File 'lib/csl/locale/term.rb', line 266 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 336
|
#masculine? ⇒ Boolean
Returns whether or not the term is masculine.
|
|
# File 'lib/csl/locale/term.rb', line 333
|
#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.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/csl/locale/term.rb', line 244 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
290 291 292 |
# File 'lib/csl/locale/term.rb', line 290 def neutral? !gendered? end |
#ordinal ⇒ Fixnum, ...
280 281 282 283 284 |
# File 'lib/csl/locale/term.rb', line 280 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.
261 262 263 |
# File 'lib/csl/locale/term.rb', line 261 def ordinal? /^(long-)?ordinal(-\d\d+)?$/ === attributes.name end |
#pluralize ⇒ Object Also known as: plural
326 327 328 329 |
# File 'lib/csl/locale/term.rb', line 326 def pluralize return text if textnode? children.multiple.to_s end |
#short? ⇒ Boolean
294 295 296 |
# File 'lib/csl/locale/term.rb', line 294 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.
271 272 273 |
# File 'lib/csl/locale/term.rb', line 271 def short_ordinal? /^ordinal(-\d\d+)?$/ === attributes.name end |
#singularize ⇒ Object Also known as: singular
319 320 321 322 |
# File 'lib/csl/locale/term.rb', line 319 def singularize return text if textnode? children.single.to_s end |
#symbol? ⇒ Boolean
306 307 308 |
# File 'lib/csl/locale/term.rb', line 306 def symbol? attribute?(:form) && attributes.form.to_s =~ /^symbol$/i end |
#tags ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/csl/locale/term.rb', line 358 def if textnode? [ "<#{[nodename, *attribute_assignments].join(' ')}>", CSL.encode_xml_text(text), "</#{nodename}>" ] else super end end |
#textnode? ⇒ Boolean
315 316 317 |
# File 'lib/csl/locale/term.rb', line 315 def textnode? !text.blank? end |
#to_s(options = nil) ⇒ String
Returns the term as a string.
379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/csl/locale/term.rb', line 379 def to_s( = nil) if textnode? text else if pluralize?() pluralize else singularize end end end |
#verb? ⇒ Boolean
298 299 300 |
# File 'lib/csl/locale/term.rb', line 298 def verb? attribute?(:form) && attributes.form.to_s =~ /^verb$/i end |
#verb_short? ⇒ Boolean
302 303 304 |
# File 'lib/csl/locale/term.rb', line 302 def verb_short? attribute?(:form) && attributes.form.to_s =~ /^verb-short$/i end |