Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INPUT = [
- {
- 'Name' => %w[
- Dominik
- Radzio
- Bartek
- ],
- 'Surname' => %w[
- Duda
- Pepek
- Monka
- ],
- 'Score' => %w[
- 10
- 6
- 1
- ]
- },
- {
- 'Score' => [
- '1 - 3',
- '4 - 6',
- '7 - 10'
- ],
- 'Label' => %w[
- Bad
- Good
- Excellent
- ]
- },
- {
- 'X' => %w[
- 34
- 77
- ],
- 'Y' => %w[
- 334
- 1
- ],
- 'Z' => %w[
- 12
- 17
- ]
- },
- {
- 'Krzys' => %w[
- 34
- 77
- ale
- ],
- 'Wojtek' => %w[
- 334
- 1
- jestem
- ],
- 'RyÅ›' => %w[
- 12
- nom
- glupi
- ],
- 'Polikarp' => %w[
- 12
- hx
- hihi
- ]
- }
- ].freeze
- class Table
- amount_tables = INPUT.each { |input| input.keys.first }
- amount = amount_tables.count
- amount.times do |x|
- length = INPUT[x].values.first.length
- raise ArgumentError, 'not eql' unless INPUT[x].values.all? { |arr| arr.length == length }
- end
- # robie tabelke zeby sie wstawiala z calym htmlowskim syntaxem
- def draw_table
- result = ''
- amount_tables = INPUT.each { |input| input.keys.first }
- amount = amount_tables.count
- amount.times do |x|
- result << "#{"\s"*3}<table>\n"
- result << "#{"\s"*5}<thead>\n"
- result << "#{"\s"*6}<tr>\n"
- INPUT[x].keys.each do |value|
- result << "#{"\s"*8}<th>#{value}</th>\n"
- end.join('')
- result << "#{"\s"*6}</tr>\n"
- result << "#{"\s"*5}</thead>\n"
- result << "#{"\s"*5}<tbody>\n"
- length = INPUT[x].values.first.count
- length.times do |row|
- result << "#{"\s"*7}<tr>\n"
- INPUT[x].values.each do |values|
- result << "#{"\s"*9}<td>#{values[row]}</td>\n"
- end
- result << "#{"\s"*7}</tr>\n"
- end
- result << "#{"\s"*5}</tbody>\n"
- result << "#{"\s"*3}</table>\n"
- result << "#{"\s"*3}<br>\n"
- end
- result
- end
- def table
- f = File.new('index2.html', 'w+')
- f.puts <<-END
- <!DOCTYPE html>
- <html>
- <body>
- <style>
- table {
- font-family: arial, sans-serif;
- border-collapse: collapse;
- width: 100%;
- }
- td, th {
- border: 1px solid #dddddd;
- text-align: left;
- padding: 8px;
- }
- tr:nth-child(even) {
- background-color: #dddddd;
- }
- </style>
- #{draw_table}
- </body>
- </html>
- END
- f.close
- end
- end
- Table.new.table
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement