Class: Marquery::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/marquery/parser.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

DATE_REGEX =
/\A(?<date>\d{8})_(?<name>[^.]+)/
CONTENT_REGEX =
/\A(?:---\n(?<frontmatter>.*?)\n---\n)?(?<body>.*)\z/m
ASSET_EXTENSIONS =
%w[.avif .gif .jpeg .jpg .mp3 .mp4 .ogg .pdf .png .svg .webm .webp].freeze
PERMITTED_YAML_CLASSES =
[Date, Time, Symbol].freeze

Instance Method Summary collapse

Constructor Details

#initialize(dir:, model:, index:, order_by:, assets_dir: nil) ⇒ Parser

Returns a new instance of Parser.



20
21
22
23
24
25
26
# File 'lib/marquery/parser.rb', line 20

def initialize(dir:, model:, index:, order_by:, assets_dir: nil)
  @dir = Pathname.new(dir.to_s)
  @assets_dir = assets_dir ? Pathname.new(assets_dir.to_s) : nil
  @model = model
  @index = index
  @order_field, @order_direction = order_by
end

Instance Method Details

#callObject



28
29
30
# File 'lib/marquery/parser.rb', line 28

def call
  Result.new(index: load_index, entries: sort(load_entries))
end