Class: ExtensionPresence
- Inherits:
-
Object
- Object
- ExtensionPresence
- Defined in:
- lib/arch_obj_models/extension.rb
Overview
Is the extension mandatory, optional, various kinds of optional, etc. Accepts two kinds of YAML schemas:
String
Example => presence: mandatory
Hash
Must have the key "optional" with a String value
Example => presence:
optional: development
Instance Attribute Summary collapse
-
#optional_type ⇒ Object
readonly
Returns the value of attribute optional_type.
-
#presence ⇒ Object
readonly
Returns the value of attribute presence.
Class Method Summary collapse
-
.mandatory ⇒ Object
Class methods.
- .optional ⇒ Object
- .optional_type_development ⇒ Object
- .optional_type_expansion ⇒ Object
- .optional_type_localized ⇒ Object
- .optional_type_transitory ⇒ Object
- .optional_types ⇒ Object
- .optional_types_obj ⇒ Object
- .presence_types ⇒ Object
- .presence_types_obj ⇒ Object
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Sorts by presence, then by optional_type.
- #==(other) ⇒ Object
-
#initialize(data) ⇒ ExtensionPresence
constructor
A new instance of ExtensionPresence.
- #mandatory? ⇒ Boolean
- #optional? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ ExtensionPresence
Returns a new instance of ExtensionPresence.
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/arch_obj_models/extension.rb', line 455 def initialize(data) if data.is_a?(String) raise "Unknown extension presence of #{data}" unless ["mandatory","optional"].include?(data) @presence = data @optional_type = nil elsif data.is_a?(Hash) data.each do |key, value| if key == "optional" raise ArgumentError, "Extension presence hash #{data} missing type of optional" if value.nil? raise ArgumentError, "Unknown extension presence optional #{value} for type of optional" unless ["localized", "development", "expansion", "transitory"].include?(value) @presence = key @optional_type = value else raise ArgumentError, "Extension presence hash #{data} has unsupported key of #{key}" end end else raise ArgumentError, "Extension presence is a #{data.class} but only String or Hash are supported" end end |
Instance Attribute Details
#optional_type ⇒ Object (readonly)
Returns the value of attribute optional_type.
452 453 454 |
# File 'lib/arch_obj_models/extension.rb', line 452 def optional_type @optional_type end |
#presence ⇒ Object (readonly)
Returns the value of attribute presence.
451 452 453 |
# File 'lib/arch_obj_models/extension.rb', line 451 def presence @presence end |
Class Method Details
.mandatory ⇒ Object
Class methods
483 |
# File 'lib/arch_obj_models/extension.rb', line 483 def self.mandatory = "mandatory" |
.optional ⇒ Object
484 |
# File 'lib/arch_obj_models/extension.rb', line 484 def self.optional = "optional" |
.optional_type_development ⇒ Object
486 |
# File 'lib/arch_obj_models/extension.rb', line 486 def self.optional_type_development = "development" |
.optional_type_expansion ⇒ Object
487 |
# File 'lib/arch_obj_models/extension.rb', line 487 def self.optional_type_expansion = "expansion" |
.optional_type_localized ⇒ Object
485 |
# File 'lib/arch_obj_models/extension.rb', line 485 def self.optional_type_localized = "localized" |
.optional_type_transitory ⇒ Object
488 |
# File 'lib/arch_obj_models/extension.rb', line 488 def self.optional_type_transitory = "transitory" |
.optional_types ⇒ Object
491 492 493 494 495 |
# File 'lib/arch_obj_models/extension.rb', line 491 def self.optional_types = [ optional_type_localized, optional_type_development, optional_type_expansion, optional_type_transitory] |
.optional_types_obj ⇒ Object
509 510 511 512 513 514 515 516 517 518 519 |
# File 'lib/arch_obj_models/extension.rb', line 509 def self.optional_types_obj return @optional_types_obj unless @optional_types_obj.nil? @optional_types_obj = [] optional_types.each do |optional_type| @optional_types_obj << ExtensionPresence.new({ self.optional => optional_type }) end @optional_types_obj end |
.presence_types ⇒ Object
490 |
# File 'lib/arch_obj_models/extension.rb', line 490 def self.presence_types = [mandatory, optional] |
.presence_types_obj ⇒ Object
497 498 499 500 501 502 503 504 505 506 507 |
# File 'lib/arch_obj_models/extension.rb', line 497 def self.presence_types_obj return @presence_types_obj unless @presence_types_obj.nil? @presence_types_obj = [] presence_types.each do |presence_type| @presence_types_obj << ExtensionPresence.new(presence_type) end @presence_types_obj end |
Instance Method Details
#<=>(other) ⇒ Object
Sorts by presence, then by optional_type
543 544 545 546 547 548 549 550 551 |
# File 'lib/arch_obj_models/extension.rb', line 543 def <=>(other) raise ArgumentError, "ExtensionPresence is only comparable to other ExtensionPresence classes" unless other.is_a?(ExtensionPresence) if @presence != other.presence @presence <=> other.presence else @optional_type <=> other.optional_type end end |
#==(other) ⇒ Boolean #==(other) ⇒ Boolean
531 532 533 534 535 536 537 538 539 540 |
# File 'lib/arch_obj_models/extension.rb', line 531 def ==(other) case other when String @presence == other when ExtensionPresence @presence == other.presence && @optional_type == other.optional_type else raise "Unexpected comparison" end end |
#mandatory? ⇒ Boolean
479 |
# File 'lib/arch_obj_models/extension.rb', line 479 def mandatory? = (@presence == mandatory) |
#optional? ⇒ Boolean
480 |
# File 'lib/arch_obj_models/extension.rb', line 480 def optional? = (@presence == optional) |
#to_s ⇒ Object
521 522 523 |
# File 'lib/arch_obj_models/extension.rb', line 521 def to_s @optional_type.nil? ? "#{presence}" : "#{presence} (#{optional_type})" end |