Class: Jekyll::Plugins::PaginateV3::Support::ProcessedValue
- Inherits:
-
Object
- Object
- Jekyll::Plugins::PaginateV3::Support::ProcessedValue
- Defined in:
- lib/jekyll-paginate-v3/support/processed_value.rb
Overview
Filter-style value preparation helper shared by existence, scalar, and range checks.
Structure: one raw resolved frontmatter value is normalised using the active split rules, then presence, type, length, and scalar-candidate questions are answered from that prepared value.
Constant Summary collapse
- TYPE_ALIASES =
{ 'datetime' => 'date' }.freeze
- SUPPORTED_TYPES =
%w[array string boolean int float date].freeze
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#array? ⇒ Boolean
Reports whether the prepared value is array-shaped.
-
#initialize(raw_value, string_array:, split: true) ⇒ ProcessedValue
constructor
A new instance of ProcessedValue.
-
#length ⇒ Object
Returns the array/string length used by length-aware range filters.
-
#present? ⇒ Boolean
Reports whether the prepared value should be treated as present.
-
#scalar_candidates ⇒ Object
Returns scalar candidates prepared for scalar/range evaluation.
-
#string? ⇒ Boolean
Reports whether the prepared value is string-shaped.
-
#type?(raw_type) ⇒ Boolean
Reports whether the prepared value satisfies one configured exists-type.
Constructor Details
#initialize(raw_value, string_array:, split: true) ⇒ ProcessedValue
Returns a new instance of ProcessedValue.
27 28 29 30 31 32 |
# File 'lib/jekyll-paginate-v3/support/processed_value.rb', line 27 def initialize(raw_value, string_array:, split: true) @raw_value = raw_value @string_array = string_array @split = split @value = prepare_value(raw_value) end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
21 22 23 |
# File 'lib/jekyll-paginate-v3/support/processed_value.rb', line 21 def value @value end |
Class Method Details
.build(raw_value, string_array:, split: true) ⇒ Object
23 24 25 |
# File 'lib/jekyll-paginate-v3/support/processed_value.rb', line 23 def self.build(raw_value, string_array:, split: true) new(raw_value, string_array: string_array, split: split) end |
Instance Method Details
#array? ⇒ Boolean
Reports whether the prepared value is array-shaped.
40 41 42 |
# File 'lib/jekyll-paginate-v3/support/processed_value.rb', line 40 def array? present? && @value.is_a?(Array) end |
#length ⇒ Object
Returns the array/string length used by length-aware range filters.
50 51 52 53 54 55 |
# File 'lib/jekyll-paginate-v3/support/processed_value.rb', line 50 def length return nil unless present? return @value.length if @value.is_a?(Array) || @value.is_a?(String) nil end |
#present? ⇒ Boolean
Reports whether the prepared value should be treated as present.
35 36 37 |
# File 'lib/jekyll-paginate-v3/support/processed_value.rb', line 35 def present? !blank_value?(@value) end |
#scalar_candidates ⇒ Object
Returns scalar candidates prepared for scalar/range evaluation.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/jekyll-paginate-v3/support/processed_value.rb', line 58 def scalar_candidates return [] unless present? return [] if @value.is_a?(Hash) if @value.is_a?(Array) return @value.flatten.compact.reject { |entry| scalar_blank?(entry) || entry.is_a?(Hash) } end scalar_blank?(@value) ? [] : [@value] end |
#string? ⇒ Boolean
Reports whether the prepared value is string-shaped.
45 46 47 |
# File 'lib/jekyll-paginate-v3/support/processed_value.rb', line 45 def string? present? && @value.is_a?(String) end |
#type?(raw_type) ⇒ Boolean
Reports whether the prepared value satisfies one configured exists-type.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/jekyll-paginate-v3/support/processed_value.rb', line 70 def type?(raw_type) type = normalise_type(raw_type) return false if type.nil? case type when 'array' array? when 'string' string? else return false unless singular_scalar? scalar_matches_type?(@value, type) end end |