ulysseslin_test_gem 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ulysseslin_test_gem.rb +47 -3
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 896f61a90ba123a8e5b4e4aac8479802e222321d
4
- data.tar.gz: f3652c9add4a5dc1b4d7ee9f9d9d6f9719521aea
3
+ metadata.gz: 2f06209383569568c3192c273c62587dd00acea9
4
+ data.tar.gz: 6f08b52b68295a94107b525f5134bc8cf682e033
5
5
  SHA512:
6
- metadata.gz: 05cc880484d5278bf04aeb0b5794e8c35bd9aa5012c5a1d2960e5a0a4d0a42c786c16a54bb7685780a10b067bbdb8013a042bf014e4b1934395997ee77fa7174
7
- data.tar.gz: cf3e73be7c33cf0fd197fdf8cc5074e8200694136320e803c049740719dbb7c4c549caacadf2cf8a9d51d1d4cdbc18e9911ad5c5fbe37c48a0234e62f212c3e2
6
+ metadata.gz: 367215e284acde2bd7d9879f7cb0974fd4bc2ff24cbc6b4ba8a02c3f1d6ab4c8282f216c7ac164470e16b42e81cd357fe9bbfb5906491019e3f63a44ee6cf56f
7
+ data.tar.gz: ff345e69e51d8e232c47aca3119bb38f25ead3f3c4b8a4aae1ee7ecec3232e4877aaac60661a9347bfece59028547c3cb7f4dec157ef429bcaee69182816b229
@@ -1,5 +1,49 @@
1
- class UlyssesLin
2
- def self.hi
3
- puts 'YUGIOH'
1
+ class Make
2
+ # If you want a custom table, you MUST provide headers as an array
3
+ # (so headers cannot be '0')
4
+ def self.table model,*rest
5
+ # These are the table keys to ignore when rendering table
6
+ @keys_to_ignore=['id','created_at','updated_at']
7
+ columns=model.column_names-@keys_to_ignore
8
+ @html='<table><thead><tr>'
9
+ # HEADER
10
+ # No headers specified; default headers used
11
+ if rest[0]==nil
12
+ columns.each {|key| @html+='<th>'+key.gsub('_',' ').titleize+'</th>'}
13
+ @html+='</tr></thead>'
14
+ # Headers specified
15
+ else
16
+ rest[0].each { |header| @html+='<th>%s</th>' % header }
17
+ @html+='</tr></thead>'
18
+ end
19
+
20
+ # BODY
21
+ @html+='<tbody>'
22
+ # Make custom table if no model given
23
+ if model==0
24
+ for r in 1..rest[2]
25
+ @html+='<tr>'
26
+ for c in 1..rest[1]
27
+ @html+='<td>%d</td>' % c
28
+ end
29
+ @html+='</tr>'
30
+ end
31
+ # Make table from given model and row limit, if any
32
+ else
33
+ limit=model.length-1
34
+ if rest[2]!=nil && rest[2]>0
35
+ limit=rest[2]-1
36
+ end
37
+ # Show rows from models array until specified or default limit
38
+ model[0..limit].each {|user|
39
+ @html+='<tr>'
40
+ user.attributes.except(*@keys_to_ignore).each {|key,val|
41
+ @html+='<td>'+val+'</td>'
42
+ }
43
+ @html+='</tr>'
44
+ }
45
+ end
46
+ @html+='</tbody></table>'
47
+ @html.html_safe
4
48
  end
5
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ulysseslin_test_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ulysses Lin
@@ -10,7 +10,8 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: A simple test gem
13
+ description: Allows user to create tables simply by referencing a table in the database
14
+ and/or defining table headers and column and row number
14
15
  email: utemoc@gmail.com
15
16
  executables: []
16
17
  extensions: []
@@ -40,5 +41,5 @@ rubyforge_project:
40
41
  rubygems_version: 2.2.2
41
42
  signing_key:
42
43
  specification_version: 4
43
- summary: 'Says: YUGIOH'
44
+ summary: Make tables from database or create custom tables
44
45
  test_files: []