duffy 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfd9a4c939fe109c02bc69dc81dc75df844298b6fc0b37eb2cd170861892ac34
4
- data.tar.gz: '08af4375c00007f03e276286fad316cf5c29a6974699312bd4881ccbc7e84485'
3
+ metadata.gz: '031931bb20a67704daaeb756697289c59b8b4b17d20542e547f44b9a810f8937'
4
+ data.tar.gz: 8d1d8ce9b7815f888604ff54be223a4efb4cecac8c5d6a8f3da7b63bb5be943b
5
5
  SHA512:
6
- metadata.gz: 941b1352de144391d63b632f3c658509c695c2b6be2036142e40eaf06f7b5ef741f074de10dd560c1fa4c4e438123dd90f7cf84be197518b45cb9c2ccf090855
7
- data.tar.gz: '0483e089f818fb5c10f8ff6ffbf22e691b72e7095c247081637327e5e81c67e59ae65ad67b34d0e1edd75eab5a1df3d2445334fb9c1f2bbd31df364b42d72edc'
6
+ metadata.gz: 7eaf20af8b3da4f7d0524fa485cf08faa159fe706a93e5d3d63e6ca58e1e38b4460eed508b4a09ebd083b3261378cb215de93bb46c0d636a7e285d0999fccd44
7
+ data.tar.gz: a33c601156a194d07e7a5675ca5ab94363181a1ccc6f2175e66fe6240e670fe1eddb454809637f47fde604a8f4de0a3c7c2d199b968a4cb2ee651ba85f63fab2
data/.gitignore CHANGED
@@ -4,7 +4,6 @@
4
4
  /Gemfile.lock
5
5
  /_yardoc/
6
6
  /coverage/
7
- /doc/
8
7
  /pkg/
9
8
  /spec/reports/
10
9
  /tmp/
@@ -13,3 +12,5 @@
13
12
  *.o
14
13
  *.a
15
14
  mkmf.log
15
+ .DS_Store
16
+
data/README.md CHANGED
@@ -19,24 +19,29 @@ And then execute:
19
19
  $ bundle
20
20
  ```
21
21
 
22
- ## Usage
23
-
24
- String Patches:
22
+ ## String Patches:
25
23
 
26
24
  Method | Example | Output
27
25
  ------------------|-----------------|-------
26
+ gender_human | "F" | "Female"
28
27
  md5 | "duffy" | "904bc6e21e4799ce276200117215b88b"
29
28
  md5sum | "duffy" | "904bc6e21e4799ce276200117215b88b"
30
- to_ssn | "123456789" | "123-45-6789"
31
- to_numeric | "abc123" | "123"
32
- to_alpha | "abc123" | "abc"
33
- to_alpha_numeric | "abc#$%123" | "abc123
29
+ nl2br | "space\nout" | "space<br/>out" (requires rails)
34
30
  pretty_phone | "1234567890" | "(123) 456-7890"
35
31
  pretty_committer | "bart" | "Bartholomew Simpson" (See config)
36
- space2nbsp | "space out" | "space&nbsp;out" (requires rails)
37
- nl2br | "space\nout" | "space<br/>out" (requires rails)
38
- gender_human | "F" | "Female"
39
32
  smart_titlecase | "this and that" | "This and That" (Note: Has config options. See lib/duffy.rb)
33
+ space2nbsp | "space out" | "space&nbsp;out" (requires rails)
34
+ to_alpha | "abc123" | "abc"
35
+ to_alpha_numeric | "abc#$%123" | "abc123
36
+ to_box | "abc".to_box | ![Example](doc/abc.png)
37
+ to_numeric | "abc123" | "123"
38
+ to_ssn | "123456789" | "123-45-6789"
39
+
40
+
41
+ ## Array Patches:
42
+ Method | Example | Output
43
+ ------------------|------------------------|-------
44
+ to_box | ['abc', 123].to_box | ![Example](doc/abc123.png)
40
45
 
41
46
 
42
47
  ## Date Patches:
@@ -44,9 +49,9 @@ smart_titlecase | "this and that" | "This and That" (Note: Has config options.
44
49
 
45
50
  Method | Example | Output
46
51
  -------------------------|-------------------------------------|-------
47
- fiscal_year | Date.today.fiscal_year | 2018
48
52
  beginning_of_fiscal_year | Date.today.beginning_of_fiscal_year | 2017-07-01
49
53
  end_of_fiscal_year | Date.today.end_of_fiscal_year | 2018-06-30
54
+ fiscal_year | Date.today.fiscal_year | 2018
50
55
 
51
56
 
52
57
  ## NilClass Patches:
@@ -66,12 +71,12 @@ habtm | has_and_belongs_to_many
66
71
 
67
72
  ## Git Access:
68
73
 
69
- Method | Result
70
- ----------|---------
71
- Duffy::Git.log | Produce tab separated listing of current git log.
74
+ Method | Result
75
+ --------------------|---------
76
+ Duffy::Git.branch | Current git branch.
72
77
  Duffy::Git.count | Count of git commits in current branch
73
78
  Duffy::Git.email | Local repo's git user.email or global if none.
74
- Duffy::Git.branch | Current git branch.
79
+ Duffy::Git.log | Produce tab separated listing of current git log.
75
80
 
76
81
 
77
82
  ## CPU Detection:
@@ -101,19 +106,13 @@ Duffy::System.mem_percent | 25
101
106
 
102
107
 
103
108
  ## View Helpers:
109
+ * Rails
104
110
 
105
111
  Method | Example | Result
106
112
  ------------|-------------------------------------|-------
107
113
  beast_mode | beast_mode tags | renders tag partial in parallel. Only available if you have the Parallel gem in your Gemfile. You must also wrap your partial in a cache block.
108
- menu_tag | menu_tag("Login", login_path) | generated hyperlinked li block used in common ul based navigation toolbars.
109
114
 
110
115
 
111
- ## CSS Reset & Print Styles: Very barebones CSS Reset / Sensible defaults and Print stylesheets.
112
- ```ruby
113
- require duffy/reset
114
- require duffy/print
115
- ```
116
-
117
116
  ## Contributing
118
117
 
119
118
  1. Fork it ( https://github.com/[my-github-username]/duffy/fork )
data/doc/abc.png ADDED
Binary file
data/doc/abc123.png ADDED
Binary file
@@ -0,0 +1,17 @@
1
+ class Array
2
+ # Make a nice box around any number of string(able) items.
3
+ # String.to_box is also available.
4
+ # Truncates at 80 characters.
5
+ # puts ["test", :info].to_box
6
+ # +------+------+
7
+ # | test | info |
8
+ # +------+------+
9
+ #
10
+ def to_box(safe: true)
11
+ return nil if self.empty?
12
+ b = safe ? "+-++ | +++" : "╔─╦╗ ║ ╚╩╝"
13
+ out = (b[0] + self.map{ |x| b[1] * (x.to_s.length + 2) }.join(b[2]) + b[3])[0,80] + "\n"
14
+ out << (b[5,2] + self.join(b[4,3]) + b[4,2])[0,80] + "\n"
15
+ out << (b[7] + self.map{ |x| b[1] * (x.to_s.length + 2) }.join(b[8]) + b[9])[0,80]
16
+ end
17
+ end
data/lib/duffy/string.rb CHANGED
@@ -7,6 +7,12 @@ class String
7
7
  end
8
8
  alias_method :md5sum, :md5
9
9
 
10
+ # Makes a nice box around your string for console output etc.
11
+ # See Array :to_box
12
+ def to_box(safe: true)
13
+ Array(self).to_box(safe: safe) unless self.empty?
14
+ end
15
+
10
16
  def to_ssn
11
17
  ssn = "%09d" % self.to_numeric.to_i # strips string of non zeros, and pads leading zeros
12
18
  ssn[0..2] + "-" + ssn[3..4] + "-" + ssn[5..8] # now it's like 123-45-6789
data/lib/duffy/version.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module Duffy
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
4
4
 
5
5
  # History
6
+ # 1.0.1 - Added String.to_box and Array.to_box. Nice for text banners.
6
7
  # 1.0.0 - Using Shellwords to escape directory listing in System.freespace.
7
8
  # 0.3.6 - Added disk freespace method. Looks at working directory.
8
9
  # 0.3.5 - Fixed linux cores detection for very high core count CPUs. Added virtualization detection on linux.
data/lib/duffy.rb CHANGED
@@ -13,6 +13,7 @@ if defined?(Rails)
13
13
  end
14
14
 
15
15
  # Normal Requirements
16
+ require File.dirname(__FILE__) + "/duffy/array"
16
17
  require File.dirname(__FILE__) + "/duffy/date"
17
18
  require File.dirname(__FILE__) + "/duffy/git"
18
19
  require File.dirname(__FILE__) + "/duffy/string"
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array do
4
+
5
+ describe "to_box" do
6
+
7
+ it "creates a safe box around a array" do
8
+ expect([:foo, 'bar'].to_box).to eq "+-----+-----+\n| foo | bar |\n+-----+-----+"
9
+ end
10
+
11
+ it "creates a fancy box around a string" do
12
+ expect([:foo, 'bar'].to_box(safe: false)).to eq "╔─────╦─────╗\n║ foo ║ bar ║\n╚─────╩─────╝"
13
+ end
14
+
15
+ it "returns nil for empty arrays" do
16
+ expect([].to_box).to eq nil
17
+ end
18
+
19
+ it "very long output is truncated" do
20
+ expect(('a'..'z').to_a.to_box.split("\n").first.length).to eq 80
21
+ end
22
+
23
+ end
24
+ end
data/spec/string_spec.rb CHANGED
@@ -1,6 +1,21 @@
1
1
  require 'spec_helper'
2
+
2
3
  describe String do
3
4
 
5
+ describe "to_box" do
6
+ it "creates a safe box around a string" do
7
+ expect("foobar".to_box).to eq "+--------+\n| foobar |\n+--------+"
8
+ end
9
+
10
+ it "creates a fancy box around a string" do
11
+ expect("foobar".to_box(safe: false)).to eq "╔────────╗\n║ foobar ║\n╚────────╝"
12
+ end
13
+
14
+ it "empty string returns nil" do
15
+ expect("".to_box).to eq nil
16
+ end
17
+
18
+ end
4
19
 
5
20
  describe "to_ssn" do
6
21
  it "maintains an already formatted SSN" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duffy
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
  - Jacob Duffy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-12 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -95,9 +95,12 @@ files:
95
95
  - LICENSE.txt
96
96
  - README.md
97
97
  - Rakefile
98
+ - doc/abc.png
99
+ - doc/abc123.png
98
100
  - duffy.gemspec
99
101
  - lib/duffy.rb
100
102
  - lib/duffy/active_record.rb
103
+ - lib/duffy/array.rb
101
104
  - lib/duffy/beast_mode_helper.rb
102
105
  - lib/duffy/date.rb
103
106
  - lib/duffy/duffy_helper.rb
@@ -107,6 +110,7 @@ files:
107
110
  - lib/duffy/string.rb
108
111
  - lib/duffy/system.rb
109
112
  - lib/duffy/version.rb
113
+ - spec/array_spec.rb
110
114
  - spec/date_spec.rb
111
115
  - spec/git_spec.rb
112
116
  - spec/nilclass_spec.rb
@@ -134,12 +138,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
138
  - !ruby/object:Gem::Version
135
139
  version: '0'
136
140
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.7.7
141
+ rubygems_version: 3.0.1
139
142
  signing_key:
140
143
  specification_version: 4
141
144
  summary: Library of things
142
145
  test_files:
146
+ - spec/array_spec.rb
143
147
  - spec/date_spec.rb
144
148
  - spec/git_spec.rb
145
149
  - spec/nilclass_spec.rb