Class: BrowserOfBabel::Holotheca
- Inherits:
-
Object
- Object
- BrowserOfBabel::Holotheca
- Extended by:
- Holarchy::ClassMethods
- Includes:
- Holarchy
- Defined in:
- lib/browser_of_babel/holotheca.rb,
lib/browser_of_babel/holotheca/holarchy.rb
Overview
Base holotheca class. From holon (Greek holos (ὅλος) meaning ‘whole’, with the suffix -on which denotes a part) and theca (Greek theke (θήκη) meaning ‘case, sheath, sleeve’ — a container).
Defined Under Namespace
Modules: Holarchy
Constant Summary collapse
- DEFAULT_URL_FORMATTER =
Trivial formatter that just calls
#to_son identifier. You probably want something more. -> { _1.to_s }
Instance Attribute Summary
Attributes included from Holarchy::ClassMethods
Attributes included from Holarchy
Class Method Summary collapse
-
.holotheca_name ⇒ String?
Get the name of the holotheca, the class name without the namespace.
-
.identifier_class ⇒ Class?
Get expected class for the holotheca’s identifier.
-
.identifier_format(format = (no_argument = true; nil)) ⇒ #===?
Get or set format validator for the holotheca’s identifier.
-
.url_format(format = (no_argument = true; nil)) ⇒ #call
Get or set string formatter for URLs.
Instance Method Summary collapse
-
#initialize(parent, identifier) ⇒ Holotheca
constructor
A new instance of Holotheca.
-
#to_s ⇒ String
Get string representation of the holotheca path.
-
#to_s_part ⇒ String
Get string representation of the holotheca: Holotheca.holotheca_name + Holarchy#identifier.
-
#to_url ⇒ String
Get string representation of the complete URI (down to this holotheca).
-
#to_url_part ⇒ String
Get string representation for use in URIs.
Methods included from Holarchy::ClassMethods
Methods included from Holarchy
#depth, #dig, #down, #path, #path_identifiers, #root, #up
Constructor Details
#initialize(parent, identifier) ⇒ Holotheca
Returns a new instance of Holotheca.
92 93 94 95 |
# File 'lib/browser_of_babel/holotheca.rb', line 92 def initialize(parent, identifier) @parent = check_parent(parent) @identifier = check_identifier(identifier) end |
Class Method Details
.holotheca_name ⇒ String?
Get the name of the holotheca, the class name without the namespace.
79 80 81 82 83 |
# File 'lib/browser_of_babel/holotheca.rb', line 79 def holotheca_name return unless name @holotheca_name ||= name.split("::").last # rubocop:disable Style/IpAddresses end |
.identifier_class ⇒ Class?
Get expected class for the holotheca’s identifier.
Depends on identifier_format:
-
a
Class— that class -
a
Regexp—String -
a
Range— class of the first element -
a
Set— class of first element if all elements are of that class (subsequent elements can be of a subclass) -
anything else —
nil(class unknown)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/browser_of_babel/holotheca.rb', line 42 def identifier_class case (validator = @identifier_format) when Class validator when Regexp String when Range validator.begin.class when Set klass = validator.first.class (validator.all? { klass === _1 }) ? klass : nil else nil end end |
.identifier_format ⇒ #===? .identifier_format(format) ⇒ #===?
Get or set format validator for the holotheca’s identifier.
23 24 25 26 27 28 29 |
# File 'lib/browser_of_babel/holotheca.rb', line 23 def identifier_format(format = (no_argument = true; nil)) # rubocop:disable Style/Semicolon return @identifier_format if no_argument return @identifier_format = format if nil == format || format.respond_to?(:===) # rubocop:disable Style/YodaCondition raise ArgumentError, "invalid format validator #{format}" end |
.url_format ⇒ #call .url_format(holotheca) ⇒ #call
Get or set string formatter for URLs.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/browser_of_babel/holotheca.rb', line 63 def url_format(format = (no_argument = true; nil)) # rubocop:disable Style/Semicolon return (@url_format ||= DEFAULT_URL_FORMATTER) if no_argument if nil == format # rubocop:disable Style/YodaCondition @url_format = DEFAULT_URL_FORMATTER elsif format.respond_to?(:call) # @type var format : _Formatter @url_format = format else raise ArgumentError, "invalid formatter #{format}" end end |
Instance Method Details
#to_s ⇒ String
Get string representation of the holotheca path.
126 127 128 |
# File 'lib/browser_of_babel/holotheca.rb', line 126 def to_s path.filter_map(&:to_s_part).join(", ") end |
#to_s_part ⇒ String
Get string representation of the holotheca: holotheca_name + BrowserOfBabel::Holotheca::Holarchy#identifier. May be empty.
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/browser_of_babel/holotheca.rb', line 112 def to_s_part if self.class.holotheca_name if identifier "#{self.class.holotheca_name} #{identifier}" else self.class.holotheca_name.to_s end else identifier.to_s end end |
#to_url ⇒ String
Get string representation of the complete URI (down to this holotheca).
105 106 107 |
# File 'lib/browser_of_babel/holotheca.rb', line 105 def to_url path.map(&:to_url_part).join end |
#to_url_part ⇒ String
Get string representation for use in URIs.
99 100 101 |
# File 'lib/browser_of_babel/holotheca.rb', line 99 def to_url_part self.class.url_format.call(identifier) end |