lib/infoboxer/media_wiki/traits.rb in infoboxer-0.2.7 vs lib/infoboxer/media_wiki/traits.rb in infoboxer-0.2.8

- old
+ new

@@ -1,6 +1,7 @@ # encoding: utf-8 + module Infoboxer class MediaWiki # DSL for defining "traits" for some site. # # More docs (and possible refactoring) to follow. @@ -17,11 +18,11 @@ # Expected to be used inside Traits definition block. def templates(&definition) @templates ||= Templates::Set.new return @templates unless definition - + @templates.define(&definition) end # @private def domain(d) @@ -57,24 +58,26 @@ # # Again, you can look at current # [English Wikipedia traits](https://github.com/molybdenum-99/infoboxer/blob/master/lib/infoboxer/definitions/en.wikipedia.org.rb) # for example implementation. def for(domain, &block) - Traits.domains[domain].tap{|c| c && c.instance_eval(&block)} || + Traits.domains[domain].tap { |c| c && c.instance_eval(&block) } || Class.new(self, &block).domain(domain) end # @private alias_method :default, :new end def initialize(options = {}) @options = options - @file_namespace = [DEFAULTS[:file_namespace], namespace_aliases(options, 'File')]. - flatten.compact.uniq - @category_namespace = [DEFAULTS[:category_namespace], namespace_aliases(options, 'Category')]. - flatten.compact.uniq + @file_namespace = + [DEFAULTS[:file_namespace], namespace_aliases(options, 'File')] + .flatten.compact.uniq + @category_namespace = + [DEFAULTS[:category_namespace], namespace_aliases(options, 'Category')] + .flatten.compact.uniq end # @private attr_reader :file_namespace, :category_namespace @@ -84,18 +87,17 @@ end private def namespace_aliases(options, canonical) - namespace = (options[:namespaces] || []).detect{|v| v.canonical == canonical} + namespace = (options[:namespaces] || []).detect { |v| v['canonical'] == canonical } return nil unless namespace - [namespace['*'], *namespace.aliases] + [namespace['*'], *namespace['aliases']] end DEFAULTS = { file_namespace: 'File', category_namespace: 'Category' - } - + }.freeze end end end