Class: DiningTable::Presenters::HTMLPresenterConfiguration::TagsConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/dining-table/presenters/html_presenter_configuration.rb

Constant Summary collapse

TAGS =
[ :table, :thead, :tbody, :tfoot, :tr, :th, :td ]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTagsConfiguration

Returns a new instance of TagsConfiguration.



64
65
66
67
68
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 64

def initialize
  TAGS.each do |tag|
    self.send("#{ tag }=", TagConfiguration.new)
  end
end

Class Method Details

.from_hash(hash) ⇒ Object



86
87
88
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 86

def self.from_hash( hash )
  new.merge_hash( hash )
end

Instance Method Details

#initialize_copy(source) ⇒ Object

for deep dup



91
92
93
94
95
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 91

def initialize_copy( source )
  TAGS.each do |tag|
    self.send("#{ tag }=", source.send( tag ).dup)
  end
end

#merge_hash(hash) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 77

def merge_hash( hash )
  return self if !hash
  tags = hash[ :tags ]
  TAGS.each do |tag|
    self.send("#{ tag }").merge_hash( tags[ tag ] )
  end if tags
  self
end

#to_hObject



70
71
72
73
74
75
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 70

def to_h
  hashes = TAGS.map do |identifier|
    self.send(identifier).to_h
  end
  { :tags => Hash[ TAGS.zip( hashes ) ] }
end