Sha256: 44a244e2613414bdb0bdf8833119caaa7734442a41651c406d1b4d46ddeec7be

Contents?: true

Size: 1.71 KB

Versions: 3

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

# Copyright (c) 2024 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'json'
require 'time'
require_relative '../factbase'

# Factbase to JSON converter.
#
# This class helps converting an entire Factbase to YAML format, for example:
#
#  require 'factbase/to_json'
#  fb = Factbase.new
#  puts Factbase::ToJSON.new(fb).json
#
# Author:: Yegor Bugayenko (yegor256@gmail.com)
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
# License:: MIT
class Factbase::ToJSON
  # Constructor.
  def initialize(fb)
    @fb = fb
  end

  # Convert the entire factbase into JSON.
  # @return [String] The factbase in JSON format
  def json
    maps = Marshal.load(@fb.export)
    maps.to_json
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
factbase-0.0.41 lib/factbase/to_json.rb
factbase-0.0.40 lib/factbase/to_json.rb
factbase-0.0.39 lib/factbase/to_json.rb