glowing-archer 0.0.1 → 0.0.2

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.
data/.DS_Store CHANGED
Binary file
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  vendor/bundle
19
+ .DS_Store
@@ -8,11 +8,12 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Glowing::Archer::VERSION
9
9
  gem.authors = ["John Griffiths"]
10
10
  gem.email = ["john@johnantoni.com"]
11
- gem.description = %q{collection of frequently used core extensions for ruby}
11
+ gem.description = %q{collection of frequently used core extensions for ruby-on-rails}
12
12
  gem.summary = %q{addons to help arrays, strings, etc. i keep on using}
13
13
  gem.homepage = "https://github.com/johnantoni/glowing-archer"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
+
16
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
19
  gem.require_paths = ["lib"]
@@ -1,7 +1,26 @@
1
- require "glowing-archer/version"
2
-
3
1
  module Glowing
4
2
  module Archer
5
- # Your code goes here...
3
+
4
+ def bootstrap_badges(badges, style = "")
5
+ style = (" " + style) unless style.nil_or_empty?
6
+ html = ""
7
+ badges.split(",").each do |badge|
8
+ badge = badge.strip
9
+ html << "<span class=\"label#{style}\">#{badge.html_safe!}</span> " unless badge.nil_or_empty?
10
+ end
11
+ return html.html_safe
12
+ end
13
+
6
14
  end
7
15
  end
16
+
17
+ require 'find'
18
+
19
+ # load all extensions
20
+ extensions_directory = File.expand_path("glowing-archer/rails", File.dirname(__FILE__))
21
+
22
+ Find.find(extensions_directory) do |path|
23
+ next if File.extname(path) != ".rb"
24
+ #puts "loading core extension: #{path}"
25
+ require path
26
+ end
@@ -0,0 +1,9 @@
1
+ Array.class_eval do
2
+ def to_h
3
+ Hash[*self.flatten]
4
+ end
5
+
6
+ def drop_nil
7
+ delete_if {|x| x == nil || x == ''}
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ module BooleanHelpers
2
+ def humanize
3
+ self ? "yes" : "no"
4
+ end
5
+ end
6
+
7
+ class FalseClass
8
+ include BooleanHelpers
9
+ end
10
+
11
+ class TrueClass
12
+ include BooleanHelpers
13
+ end
14
+
@@ -0,0 +1,9 @@
1
+ class Numeric
2
+ def percents
3
+ self * 100
4
+ end
5
+
6
+ def percent_of(n)
7
+ self.to_f / n.to_f * 100.0
8
+ end
9
+ end
@@ -0,0 +1,70 @@
1
+ String.class_eval do
2
+ def to_bool
3
+ return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
4
+ return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
5
+ raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
6
+ end
7
+
8
+ def uncapitalize
9
+ self[0, 1].downcase + self[1..-1]
10
+ end
11
+
12
+ def append_url_params(params)
13
+ param_str = params.stringify_keys.reject {|k,v| v.blank? || self =~ /[\?&]#{CGI.escape(k)}=/}.map{|k,v|"#{CGI.escape(k)}=#{CGI.escape(v)}"}.join('&')
14
+ return self if param_str.blank?
15
+
16
+ [self, param_str].join(self.index('?') ? '&' : '?')
17
+ end
18
+
19
+ def truncate(n)
20
+ self[0...n]
21
+ end
22
+
23
+ def parse_brackets
24
+ self.scan(/\((.*?)\)/).flatten
25
+ end
26
+
27
+ def parse_curly_brackets
28
+ self.scan(/\{(.*?)\}/).flatten
29
+ end
30
+
31
+ def remove_brackets
32
+ self[(self.rindex(")") + 1)..-1].strip
33
+ end
34
+
35
+ def is_a_number?
36
+ self.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
37
+ end
38
+
39
+ def html_safe!
40
+ CGI::escapeHTML(self)
41
+ end
42
+
43
+ # miss this method from js
44
+ def trim
45
+ self.strip
46
+ end
47
+
48
+ # get first character of string
49
+ def initial
50
+ self[0,1]
51
+ end
52
+
53
+ # get first character of string and titleize
54
+ def initial!
55
+ self.initial.upcase + "."
56
+ end
57
+
58
+ end
59
+
60
+ class NilClass
61
+ def nil_or_empty?
62
+ true
63
+ end
64
+ end
65
+
66
+ class String
67
+ def nil_or_empty?
68
+ empty?
69
+ end
70
+ end
@@ -1,5 +1,5 @@
1
1
  module Glowing
2
2
  module Archer
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glowing-archer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,7 +27,7 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
- description: collection of frequently used core extensions for ruby
30
+ description: collection of frequently used core extensions for ruby-on-rails
31
31
  email:
32
32
  - john@johnantoni.com
33
33
  executables: []
@@ -42,6 +42,10 @@ files:
42
42
  - Rakefile
43
43
  - glowing-archer.gemspec
44
44
  - lib/glowing-archer.rb
45
+ - lib/glowing-archer/rails/array.rb
46
+ - lib/glowing-archer/rails/boolean.rb
47
+ - lib/glowing-archer/rails/numeric.rb
48
+ - lib/glowing-archer/rails/string.rb
45
49
  - lib/glowing-archer/version.rb
46
50
  homepage: https://github.com/johnantoni/glowing-archer
47
51
  licenses: []
@@ -57,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
57
61
  version: '0'
58
62
  segments:
59
63
  - 0
60
- hash: 3937140313005898380
64
+ hash: -3349905922884161736
61
65
  required_rubygems_version: !ruby/object:Gem::Requirement
62
66
  none: false
63
67
  requirements:
@@ -66,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
70
  version: '0'
67
71
  segments:
68
72
  - 0
69
- hash: 3937140313005898380
73
+ hash: -3349905922884161736
70
74
  requirements: []
71
75
  rubyforge_project:
72
76
  rubygems_version: 1.8.23