Sha256: 5cc03737f53f1b6cc9438dfbfe8450282a37f216e7a262f98d2857134bf89005
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
require 'rhet-butler/yaml-type' module RhetButler class LayoutRule include YamlType def initialize @match = {} @layout_args = nil end attr_accessor :match, :layout_type, :layout_args def self.optional_config %w[match] end def self.required_config %w[layout] end def init_with(coder) @config_hash = case coder.type when :seq { 'match' => coder.seq[0], 'layout' => coder.seq[1] } when :map coder.map else raise "Tried to configure a layout rule with non-sequence: #{coder.inspect}" end check_config_hash(@config_hash) value_from_config("match") do |value| if value == 'default' @match = {} else @match = value end end @layout_type, @layout_args = *@config_hash['layout'] end def layout Arrangement[@layout_type].new(*(@layout_args||[])) end def match?(group) @match.all? do |key, value| target = group.metadata.fetch(key) value === target end rescue KeyError false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rhet-butler-0.5.0 | lib/rhet-butler/layout-rule.rb |