class Factbook::Profile

Public Class Methods

new() click to toggle source
# File lib/factbook-fields/profile.rb, line 19
def initialize
  @categories = {}
end
read( path ) click to toggle source

attr_reader :categories ## “structured” access e.g. categories/fields/etc.

use each for access by default for categories - why? why not?
# File lib/factbook-fields/profile.rb, line 12
def self.read( path )   ## convenience helper
  text = File.open( path, 'r:utf-8' ) { |f| f.read }
  b = ProfileBuilder.new( text )
  b.profile
end

Public Instance Methods

<<( category )
Alias for: add
[](key) click to toggle source
# File lib/factbook-fields/profile.rb, line 28
def [](key)  ### convenience shortcut
  if key.is_a?( Integer )  ## allow access by 0,1,2, etc.
    @categories.values[ key ]
  else
    @categories[key]
  end
end
add( category ) click to toggle source
# File lib/factbook-fields/profile.rb, line 23
def add( category )
  @categories[ category.title ] = category
end
Also aliased as: <<
size() click to toggle source
# File lib/factbook-fields/profile.rb, line 36
def size()   @categories.size; end
to_h() click to toggle source
# File lib/factbook-fields/profile.rb, line 40
def to_h
  data = {}
  @categories.each do |_,category|
     data[ category.title ] = category.data
  end
  data
end
to_json( minify: false ) click to toggle source
# File lib/factbook-fields/profile.rb, line 48
def to_json( minify: false )  ## convenience helper for data.to_json; note: pretty print by default!
  if minify
    to_h.to_json
  else ## note: pretty print by default!
    JSON.pretty_generate( to_h )
  end
end