class Bliss::Format

Public Class Methods

new(filepath) click to toggle source
# File lib/bliss/format.rb, line 7
def initialize(filepath)
  self.specifications = YAML.load_file(filepath)
end
settings_to_constraints(depth, settings) click to toggle source
# File lib/bliss/format.rb, line 54
def self.settings_to_constraints(depth, settings)
  # TODO perhaps the Constraint model should handle this
  # e.g., constraint.add_depth (as array)
  # then internally it creates xpath-like depth

  current_constraints = []
  depth_name = nil
  content_values = nil
  #puts "#{depth.join('/')}: #{settings.inspect}"
  settings.each_pair { |setting, value|
    case setting
      when "tag_name_required"
        if value == true
          depth_name ||= depth.join('/')
          current_constraints.push(Bliss::Constraint.new(depth_name, :tag_name_required))
        end
      when "tag_name_values"
        depth_name = depth[0..-2].join('/')
        depth_name << "/" if depth_name.size > 0
        depth_name << "(#{value.join('|')})" # TODO esto funciona solo en el ultimo step del depth :/
      when "content_values"
        current_constraints.push(Bliss::Constraint.new(depth_name, :content_values, {:possible_values => value}))
    end
  }
  current_constraints.each {|cc|
    cc.depth = depth_name
  }
  current_constraints
end

Public Instance Methods

constraints() click to toggle source
# File lib/bliss/format.rb, line 21
def constraints
  return [] if not (@specs.is_a? Hash and @specs.size > 0)
  return @constraints if @constraints

  @constraints = []

  @specs.recurse(true) do |depth, value|
    if value.is_a? Hash and !@@keywords.include?(depth.last)
      settings = value.select { |key| @@keywords.include?(key) }
    end
    #settings = @specs.value_at_chain(depth).select{|key| @@keywords.include?(key) }
    if settings.is_a? Hash and !@@keywords.include?(depth.last)
      settings.merge!({"tag_name_required" => true}) if not settings.has_key?("tag_name_required")

      # TODO this is an ugly way to move tag_name_values to the end!
      settings.store('tag_name_values', settings.delete('tag_name_values')) if settings.has_key?('tag_name_values')
      settings.store('content_values', settings.delete('content_values')) if settings.has_key?('content_values')

      #puts settings.inspect

      #depth_name = nil
      #setting_to_constraints(depth, settings).each { |cc|
        #cc.depth = depth_name
      #  @constraints.push(cc) #Bliss::Constraint.new(depth_name, cc.setting))
      #}
      @constraints.concat(Bliss::Format.settings_to_constraints(depth, settings))

    end
  end

  return @constraints
end
details() click to toggle source
# File lib/bliss/format.rb, line 113
def details
  @constraints.collect(&:detail)
end
error_details() click to toggle source
# File lib/bliss/format.rb, line 117
def error_details
  @constraints.select {|c| c.state == :not_passed }.collect(&:detail)
end
keywords() click to toggle source

TODO for debugging only!

# File lib/bliss/format.rb, line 12
def keywords
  @@keywords
end
specifications=(specs={}) click to toggle source
# File lib/bliss/format.rb, line 16
def specifications=(specs={})
  @specs = specs.dup
end
Also aliased as: specs=
specs=(specs={})
Alias for: specifications=
to_check_constraints() click to toggle source

constraint set model? constraints.valid.with_depth([‘root’, ‘ads’]) ???

# File lib/bliss/format.rb, line 103
def to_check_constraints
  # raise error if not depth.is_a? Array
  begin
    to_check_constraints = constraints.select {|c| [:not_checked, :passed].include?(c.state) }
    to_check_constraints
  rescue
    []
  end
end