class Textoken::Options

Creates collection array, checks basic hash format. Responds to collection as an array of options sorted by priority. Does not raise an exception when options are nil

Attributes

options[R]

Public Class Methods

new(opt) click to toggle source
# File lib/textoken/options.rb, line 8
def initialize(opt)
  @options = opt
  @collection = []
  check_options_format
end

Public Instance Methods

collection() click to toggle source
# File lib/textoken/options.rb, line 14
def collection
  options.each { |k, v| init_option(k, v) } if options
  sort_collection
  @collection
end

Private Instance Methods

check_options_format() click to toggle source
# File lib/textoken/options.rb, line 22
def check_options_format
  return if options.nil? || options.is_a?(Hash)
  Textoken.expression_err("#{options} is not a valid format, you can use;
    Textoken('Alfa beta.', exclude: 'dates, phones', more_than: 3)")
end
init_option(key, value) click to toggle source
# File lib/textoken/options.rb, line 28
def init_option(key, value)
  @collection << Textoken::OptionFactory.build(key, value)
end
sort_collection() click to toggle source
# File lib/textoken/options.rb, line 32
def sort_collection
  @collection.sort! { |a, b| a.priority <=> b.priority }
end