hiro_format 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f96bf9fe44818eab0773d61c7d5105ef411b150
4
- data.tar.gz: d1f57179c47e28cc096253e3c7b8445c1c33a7b0
3
+ metadata.gz: c1b0944ba990e29090b661200cdbe29963e1b388
4
+ data.tar.gz: ad059da42abe249fd5b2c33d2b32ccdcf9884499
5
5
  SHA512:
6
- metadata.gz: 6ff10774dcccc2a73b6292e854b70f6995b9c5f7c1e285ebc411313eccc133efae548a7cb2af21ee352caf443edff8e78e122772ec6d21e3159039ad77864dec
7
- data.tar.gz: ee9aa9b3df5fa6938bc0f387dfaa24095f6a83b5566cf8b18e96299bebda71bd571a882e10e2224c1160d4a60c378ec656ee9ed572a387d2cefc4107c896d77b
6
+ metadata.gz: 2e51014e44811ffb27ec9df658328ee6efd2cf642e828e7953fce16540a31eef81518e16152efb38a52ada9f429e0cee288e8815762905051b73ab78d8520d6b
7
+ data.tar.gz: 961c3417cd7ffa6338f4e9dc7fc8517e8035921af6ab57d43e3b1ae482b2dfcb002f4f5327dc831d46ef3ebb60334739dc3e3ec2626b4f3408b28b548387edad
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Hiro UTSUMI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # HiroFormat
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hiro_format`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ HiroFormat (hiro_format) is a text formatter.
4
+
5
+ It converts ruby variables into formatted text by predefined recipe.
6
+ It also supports ANSI color display for console applications, and html class handling to have colorful texts.
7
+
4
8
 
5
- TODO: Delete this and the text above, and describe your gem
6
9
 
7
10
  ## Installation
8
11
 
@@ -20,16 +23,43 @@ Or install it yourself as:
20
23
 
21
24
  $ gem install hiro_format
22
25
 
23
- ## Usage
26
+ ## Usage samples
27
+
28
+ ~~~ruby
29
+ require 'hiro_format'
30
+
31
+ puts "This is a text string".color(:red_marker).to_s
32
+ value = 123456.78
33
+ puts value.formatting(:commify).color(:blue).to_s # 123,456.78 (Blue color)
34
+ puts Formatting.new(Date.today, :jp_date).color(:magenta_marker).to_s # 2017-12-24
35
+ puts Date.today.formatting(:euro_date).color(:reverse).to_s # 24-12-2017
36
+ puts Formatting.new(Date.today, :us_date).color("magenta").to_span # <span class="magenta">12-24-2017</span>
37
+ # pzm means Plus/Zero/Minus
38
+ puts -1.formatting(:digit2).pzm?(:green, :hide, :red).to_s # -01 (Red)
39
+ puts 0.formatting(:digit2).pzm?(:green, :hide, :red).to_s # (No show)
40
+ puts 1.formatting(:digit6).pzm(value, :green, :hide, :red).to_s # 000002 (Green)
41
+ ~~~
42
+
43
+ ## Formatting Recipes
24
44
 
25
- TODO: Write usage instructions here
45
+ :date, :datetime, :machine_date, :commify, and more
26
46
 
27
- ## Development
47
+ See Help file for details at : (TODO)
28
48
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+ ## Coloring Recipes
30
50
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+ :hide, :red, :red_bold, :red_back, :red_marker, :yellow, :reverse, and more
52
+
53
+ See Help file for details at : (TODO)
54
+
55
+ ## TODO
56
+
57
+ Project just started. A lot to do.
32
58
 
33
59
  ## Contributing
34
60
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hiro_tools.
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/gambaldia/hiro_tools.
62
+
63
+ ## Licence
64
+
65
+ MIT
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Formatting Class Usage Example
4
+ #
5
+ # Hiro Utsumi (Github: Gambaldia) - Zolder, Belgium
6
+ #
7
+ #
8
+ # 2017-07-24 Start
9
+ #
10
+
11
+ # Following lines are needed if you clone this from GitHub
12
+ APP_ROOT = File.dirname(__FILE__)
13
+ $LOAD_PATH << "#{APP_ROOT}/lib"
14
+ require "hiro_format/formatting"
15
+ require "hiro_format/coloring"
16
+ #require "pry" # gem install pry pry-byebug
17
+
18
+ value = 123456.78
19
+ puts value.formatting(:commify).color(:blue).to_s
20
+ puts Formatting.new(Date.today, :us_date).color(:magenta_marker).to_s
21
+ puts Date.today.formatting(:euro_date).color(:reverse).to_s
22
+ puts Date.today.formatting(:machine_date).color(:cyan_bold).to_s
23
+ puts "#pzm (Plus, Zero, Minus) can show in different color depending on the value passed."
24
+ [-1, 0, 1].each do |n|
25
+ puts n.formatting(:digit6).pzm(:reverse, :red_marker, :magenta_marker).to_s
26
+ end
27
+ puts "Formatting helper for HTML, you set your color in CSS (Cyan Marker)".color(:cyan_marker).to_s
28
+ puts Formatting.new(Date.today, :us_date).color("magenta").to_span # <span class="magenta">12-24-2017</span>
29
+
30
+ AnsiColoring.show_list
Binary file
@@ -62,7 +62,7 @@
62
62
 
63
63
  def initialize(data, color_scheme)
64
64
  @data = data
65
- @color_scheme = nil
65
+ @color_scheme = color_scheme
66
66
  end
67
67
 
68
68
  def to_s
@@ -81,10 +81,12 @@
81
81
  end
82
82
 
83
83
  def self.show_list
84
- puts "Color schemes list:"
84
+ puts "Color scheme list:"
85
85
  COLOR_SCHEMES.each do |key, scheme|
86
- puts AnsiColoring.colorize(key, key)
86
+ print AnsiColoring.colorize(key, key)
87
+ print ", "
87
88
  end
89
+ puts
88
90
  end
89
91
 
90
92
  end
@@ -6,10 +6,7 @@
6
6
  #
7
7
  # 2017-07-22 Start
8
8
  #
9
- APP_ROOT = File.dirname(__FILE__)
10
- $LOAD_PATH << "#{APP_ROOT}"
11
9
  require 'date'
12
- require 'coloring'
13
10
 
14
11
  class Formatting
15
12
  YOUBI = %w[日 月 火 水 木 金 土]
@@ -36,8 +33,8 @@ require 'coloring'
36
33
  :euro_datetimesecond => {:time_format => "%d-%m-%Y %H:%M:%s", :applicable => [Date, DateTime, Time], :rest => "0000-00-00 00:00:00" },
37
34
  :machine_datetime => {:time_format => "%Y%m%d%H%M", :applicable => [Date, DateTime], :rest => "000000000000" },
38
35
 
39
- :digit6 =>{:format => "%06d", :applicable => [Integer, Float], :rest => "000000"},
40
- :digit2 =>{:format => "%02d", :applicable => [Integer, Float], :rest => "00"},
36
+ :digit6 =>{:format => "%06d", :applicable => [Fixnum, Integer, Float], :rest => "000000"},
37
+ :digit2 =>{:format => "%02d", :applicable => [Fixnum, Integer, Float], :rest => "00"},
41
38
 
42
39
  :func =>{:function => "", :applicable => [], :rest => ""},
43
40
  }.freeze
@@ -52,7 +49,7 @@ require 'coloring'
52
49
  self
53
50
  end
54
51
 
55
- def pzm?(plus, zero, minus)
52
+ def pzm(plus, zero, minus)
56
53
  judge = @data.to_f
57
54
  if judge > 0.0
58
55
  @color_scheme = plus
@@ -64,7 +61,7 @@ require 'coloring'
64
61
  self
65
62
  end
66
63
 
67
- def pzm(judge, plus, zero, minus)
64
+ def pzm?(judge, plus, zero, minus)
68
65
  judge = judge.to_f
69
66
  if judge > 0.0
70
67
  @color_scheme = plus
@@ -97,8 +94,9 @@ require 'coloring'
97
94
 
98
95
  def to_string
99
96
  if @formatting_option.nil?
100
- #result = ""
97
+ #result = @data.to_s
101
98
  elsif recipe = FORMATTER_LIST[@formatting_option]
99
+ # puts @data.class
102
100
  if recipe[:applicable].include?(@data.class)
103
101
  if recipe[:time_format]
104
102
  result = @data.strftime(recipe[:time_format])
@@ -116,10 +114,9 @@ require 'coloring'
116
114
 
117
115
  def to_s
118
116
  result = to_string
119
- if @color_scheme
117
+ if @color_scheme && AnsiColoring
120
118
  result = AnsiColoring.colorize(result, @color_scheme)
121
119
  end
122
- #binding.pry
123
120
  result
124
121
  end
125
122
  alias show to_s
@@ -213,13 +210,3 @@ require 'coloring'
213
210
  Formatting.new(self, option)
214
211
  end
215
212
  end
216
-
217
- if (__FILE__ == $0)
218
- $verbose = true
219
- [0, 1234, 12345.67, "test", Date.today, Time.now].each do |value|
220
- [:html, :commify, :jp_datewday].each do |fmt|
221
- puts "#{value}->#{fmt}: #{value.formatting(fmt).to_s}"
222
- end
223
- end
224
- AnsiColoring.show_list
225
- end
@@ -1,3 +1,3 @@
1
1
  module HiroFormat
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiro_format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiro Utsumi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-23 00:00:00.000000000 Z
11
+ date: 2017-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -47,10 +47,13 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
49
  - Gemfile
50
+ - LICENSE
50
51
  - README.md
51
52
  - Rakefile
52
53
  - bin/console
53
54
  - bin/setup
55
+ - formatting_samples.rb
56
+ - hiro_format-0.0.1.gem
54
57
  - hiro_format.gemspec
55
58
  - lib/hiro_format.rb
56
59
  - lib/hiro_format/coloring.rb