bootstripe 0.2.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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bootstripe/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bootstripe"
7
+ s.version = Bootstripe::VERSION
8
+ s.authors = ["Mike Laurence"]
9
+ s.email = ["mike@bytebin.com"]
10
+ s.homepage = "http://bytebin.com"
11
+ s.summary = %q{A handful of useful additions for Ruby}
12
+ s.description = %q{A handful of useful additions for Ruby}
13
+
14
+ s.rubyforge_project = "bootstripe"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,21 @@
1
+ class Array
2
+ def mean
3
+ sum / size
4
+ end
5
+
6
+ def count(&action)
7
+ return size unless block_given?
8
+ self.inject(0){ |memo,item| memo += 1 if action.call(item); memo }
9
+ end
10
+
11
+ def compakt
12
+ self.reject do |i|
13
+ (i.respond_to?(:length) && i.length == 0) ||
14
+ (i.respond_to?(:match) && i.match(/^\s+$/))
15
+ end
16
+ end
17
+
18
+ def random(num_elements = 1)
19
+ num_elements == 1 ? self[Kernel.rand(size)] : sort_by{ Kernel.rand }.slice(0...num_elements)
20
+ end
21
+ end
@@ -0,0 +1,39 @@
1
+ module DateAdditions
2
+ def future_in_words
3
+ the_day = self.to_date
4
+ day_name = the_day.strftime("%A")
5
+
6
+ case the_day
7
+ when Date.current then "Today"
8
+ when Date.current + 1 then "Tomorrow"
9
+
10
+ when the_day <= (Date.current + 6.days).to_date then "this coming #{day_name} the #{the_day.day.ordinalize}"
11
+ when the_day <= (Date.current + 13.days).to_date then "next #{day_name} the #{the_day.day.ordinalize}"
12
+ else "#{the_day.strftime('%A %b')} #{the_day.day.ordinalize}"
13
+ end
14
+ end
15
+ end
16
+
17
+ # https://gist.github.com/896635
18
+ class Time
19
+ include DateAdditions
20
+ class << self
21
+ def next(day, from = nil)
22
+ day = [:sunday,:monday,:tuesday,:wednesday,:thursday,:friday,:saturday].find_index(day) if day.class == Symbol
23
+ one_day = 60 * 60 * 24
24
+ original_date = from || current
25
+ result = original_date
26
+ result += one_day until result > original_date && result.wday == day
27
+ result
28
+ end
29
+ end
30
+ end
31
+
32
+ class Date
33
+ include DateAdditions
34
+ def to_time
35
+ #Convert a fraction of a day to a number of microseconds
36
+ usec = (sec_fraction * 60 * 60 * 24 * (10**6)).to_i
37
+ Time.gm(year, month, day, hour, min, sec, usec)
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ class Numeric
2
+ def to_period(brief = false)
3
+ total_seconds = self.to_i
4
+
5
+ days = total_seconds / 86400
6
+ hours = (total_seconds / 3600) - (days * 24)
7
+ minutes = (total_seconds / 60) - (hours * 60) - (days * 1440)
8
+ seconds = total_seconds % 60
9
+
10
+ display = ''
11
+ display_concat = ''
12
+ if days > 0
13
+ display = display + display_concat + "#{days}d"
14
+ display_concat = ' '
15
+ end
16
+ if hours > 0
17
+ display = display + display_concat + "#{hours}h"
18
+ display_concat = ' '
19
+ end
20
+ if minutes > 0 and (!brief or days == 0)
21
+ display = display + display_concat + "#{minutes}m"
22
+ display_concat = ' '
23
+ end
24
+ if seconds > 0 and (!brief or days == 0)
25
+ display = display + display_concat + "#{seconds}s"
26
+ end
27
+ display
28
+ end
29
+
30
+ def to_formatted_time
31
+ return '00:00' if self == 0
32
+
33
+ minutes = (self / 60).floor
34
+ seconds = (self % 60).round
35
+ minutes = '0' + minutes.to_s if minutes.to_s.length == 1
36
+ seconds = '0' + seconds.to_s if seconds.to_s.length == 1
37
+ "#{minutes}:#{seconds}"
38
+ end
39
+
40
+ end
41
+
42
+ class BigDecimal
43
+ def as_json(options = {})
44
+ to_f
45
+ end
46
+ end
@@ -0,0 +1,13 @@
1
+ class String
2
+ def decapitalize!
3
+ replace (self.reverse.chop + self.reverse.last.downcase).reverse
4
+ end
5
+
6
+ def decapitalize
7
+ dup.decapitalize!
8
+ end
9
+
10
+ def to_class
11
+ Object.const_get(self)
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Bootstripe
2
+ VERSION = "0.2.2"
3
+ end
@@ -0,0 +1,17 @@
1
+ class WwwMiddleware
2
+ def initialize(app)
3
+ @app = app
4
+ end
5
+
6
+ def call(env)
7
+ request = Rack::Request.new(env)
8
+ if request.host.starts_with?("www.")
9
+ [301, {"Location" => request.url.sub("//www.", "//")}, self]
10
+ else
11
+ @app.call(env)
12
+ end
13
+ end
14
+
15
+ def each(&block)
16
+ end
17
+ end
data/lib/bootstripe.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'bootstripe/version'
2
+
3
+ # Additions
4
+ require 'bootstripe/array_additions'
5
+ require 'bootstripe/date_additions'
6
+ require 'bootstripe/number_additions'
7
+ require 'bootstripe/string_additions'
8
+
9
+ # Middleware
10
+ require 'bootstripe/www_middleware'
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array do
4
+
5
+ it 'should compact blank objects and leave non-blank objects in place' do
6
+ [0, 1, 2, 3].compakt.should == [0, 1, 2, 3]
7
+ [0, '', :symbol].compakt.should == [0, :symbol]
8
+ [[], [1, 2]].compakt.should == [[1, 2]]
9
+ [{ :stuff => :junk }, {}, 'stuff'].compakt.should == [{ :stuff => :junk }, 'stuff']
10
+ [' ', ' I need trimming! '].compakt.should == [' I need trimming! ']
11
+ end
12
+
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Numeric do
4
+
5
+ it 'should report 00:00' do
6
+ 0.to_formatted_time.should eq '00:00'
7
+ end
8
+
9
+ it 'should report 01:01' do
10
+ (60.75).to_formatted_time.should eq '01:01'
11
+ end
12
+
13
+ it 'should report 11:13' do
14
+ (673.2).to_formatted_time.should eq '11:13'
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'bootstripe'
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstripe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mike Laurence
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70273530058540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70273530058540
25
+ description: A handful of useful additions for Ruby
26
+ email:
27
+ - mike@bytebin.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - bootstripe.gemspec
36
+ - lib/bootstripe.rb
37
+ - lib/bootstripe/array_additions.rb
38
+ - lib/bootstripe/date_additions.rb
39
+ - lib/bootstripe/number_additions.rb
40
+ - lib/bootstripe/string_additions.rb
41
+ - lib/bootstripe/version.rb
42
+ - lib/bootstripe/www_middleware.rb
43
+ - spec/array_additions_spec.rb
44
+ - spec/number_additions_spec.rb
45
+ - spec/spec_helper.rb
46
+ homepage: http://bytebin.com
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project: bootstripe
66
+ rubygems_version: 1.8.11
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: A handful of useful additions for Ruby
70
+ test_files:
71
+ - spec/array_additions_spec.rb
72
+ - spec/number_additions_spec.rb
73
+ - spec/spec_helper.rb