cm_lograge_formatter 0.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 +7 -0
- data/.gitignore +57 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +38 -0
- data/cm_lograge_formatter.gemspec +19 -0
- data/lib/cm_lograge_formatter.rb +28 -0
- data/spec/cm_lograge_formatter_spec.rb +33 -0
- data/spec/spec_helper.rb +6 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 83b61f2575f2c7af0dc976efad4aea555cf2f9e4
|
4
|
+
data.tar.gz: b3d5ac36522d4ff8613182f1e5de82ca1b75f460
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c06adf9fdd6b781ae351758633303988689ec460d01417759de53fee752cf0552869d4dee374ce2a4a2a35eb0ff4fd3132c8436712d39a407ff2d8d776e131ce
|
7
|
+
data.tar.gz: bf43aaf4f4e2cf2df87459fd85940959fdc02983bc141b9abce38c18230d95a80943a158cd40f24c10d1c41024846976dc05087d0da3405d840e597f814f4fd9
|
data/.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
# Created by https://www.gitignore.io/api/ruby
|
3
|
+
|
4
|
+
### Ruby ###
|
5
|
+
*.gem
|
6
|
+
*.rbc
|
7
|
+
/.config
|
8
|
+
/coverage/
|
9
|
+
/InstalledFiles
|
10
|
+
/pkg/
|
11
|
+
/spec/reports/
|
12
|
+
/spec/examples.txt
|
13
|
+
/test/tmp/
|
14
|
+
/test/version_tmp/
|
15
|
+
/tmp/
|
16
|
+
|
17
|
+
# Used by dotenv library to load environment variables.
|
18
|
+
# .env
|
19
|
+
|
20
|
+
## Specific to RubyMotion:
|
21
|
+
.dat*
|
22
|
+
.repl_history
|
23
|
+
build/
|
24
|
+
*.bridgesupport
|
25
|
+
build-iPhoneOS/
|
26
|
+
build-iPhoneSimulator/
|
27
|
+
|
28
|
+
## Specific to RubyMotion (use of CocoaPods):
|
29
|
+
#
|
30
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
31
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
32
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
33
|
+
#
|
34
|
+
# vendor/Pods/
|
35
|
+
|
36
|
+
## Documentation cache and generated files:
|
37
|
+
/.yardoc/
|
38
|
+
/_yardoc/
|
39
|
+
/doc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalization:
|
43
|
+
/.bundle/
|
44
|
+
/vendor/bundle
|
45
|
+
/lib/bundler/man/
|
46
|
+
|
47
|
+
# for a library or gem, you might want to ignore these files since the code is
|
48
|
+
# intended to run in multiple environments; otherwise, check them in:
|
49
|
+
# Gemfile.lock
|
50
|
+
# .ruby-version
|
51
|
+
# .ruby-gemset
|
52
|
+
|
53
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
54
|
+
.rvmrc
|
55
|
+
|
56
|
+
|
57
|
+
# End of https://www.gitignore.io/api/ruby
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cm_lograge_formatter (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
method_source (0.9.0)
|
12
|
+
pry (0.11.3)
|
13
|
+
coderay (~> 1.1.0)
|
14
|
+
method_source (~> 0.9.0)
|
15
|
+
rspec (3.7.0)
|
16
|
+
rspec-core (~> 3.7.0)
|
17
|
+
rspec-expectations (~> 3.7.0)
|
18
|
+
rspec-mocks (~> 3.7.0)
|
19
|
+
rspec-core (3.7.1)
|
20
|
+
rspec-support (~> 3.7.0)
|
21
|
+
rspec-expectations (3.7.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.7.0)
|
24
|
+
rspec-mocks (3.7.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-support (3.7.1)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
cm_lograge_formatter!
|
34
|
+
pry
|
35
|
+
rspec (~> 3.6)
|
36
|
+
|
37
|
+
BUNDLED WITH
|
38
|
+
1.16.1
|
@@ -0,0 +1,19 @@
|
|
1
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
2
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'cm_lograge_formatter'
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.date = '2018-06-04'
|
8
|
+
s.summary = "Key Value formatter and no newline in value"
|
9
|
+
s.description = "Key Value formatter and no newline in value"
|
10
|
+
s.authors = ["ben"]
|
11
|
+
s.email = 'ben@codementor.ios'
|
12
|
+
s.files = `git ls-files`.split($/)
|
13
|
+
s.homepage =
|
14
|
+
'https://github.com/codementordev/cm_lograge_formatter'
|
15
|
+
s.license = 'MIT'
|
16
|
+
s.required_ruby_version = '>= 2.3'
|
17
|
+
|
18
|
+
s.add_development_dependency("rspec", ["~> 3.6"])
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class CmLogrageFormatter
|
2
|
+
def call(data)
|
3
|
+
fields_to_display(data)
|
4
|
+
.map { |key| format(key, data[key]) }
|
5
|
+
.join(' ')
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def fields_to_display(data)
|
11
|
+
data.keys
|
12
|
+
end
|
13
|
+
|
14
|
+
def format(key, value)
|
15
|
+
"#{key}=#{parse_value(key, value)}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_value(key, value)
|
19
|
+
if value.is_a? Float
|
20
|
+
Kernel.format('%.2f', value)
|
21
|
+
elsif value.is_a? String
|
22
|
+
safe_value = value.gsub("\n", "\t")
|
23
|
+
"'#{safe_value}'"
|
24
|
+
else
|
25
|
+
value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CmLogrageFormatter' do
|
4
|
+
describe '#call' do
|
5
|
+
let(:formatter) do
|
6
|
+
CmLogrageFormatter.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should foramt hash" do
|
10
|
+
data = { foo: "bar", baz: 123 }
|
11
|
+
|
12
|
+
result = formatter.call(data)
|
13
|
+
|
14
|
+
expect(result).to eq("foo='bar' baz=123")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should replace newline with \t" do
|
18
|
+
data = { foo: "bar\n123", baz: 123 }
|
19
|
+
|
20
|
+
result = formatter.call(data)
|
21
|
+
|
22
|
+
expect(result).to eq("foo='bar\t123' baz=123")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should adjust float format" do
|
26
|
+
data = { foo: "bar", baz: 123.45678 }
|
27
|
+
|
28
|
+
result = formatter.call(data)
|
29
|
+
|
30
|
+
expect(result).to eq("foo='bar' baz=123.46")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cm_lograge_formatter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ben
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.6'
|
27
|
+
description: Key Value formatter and no newline in value
|
28
|
+
email: ben@codementor.ios
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- cm_lograge_formatter.gemspec
|
37
|
+
- lib/cm_lograge_formatter.rb
|
38
|
+
- spec/cm_lograge_formatter_spec.rb
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
homepage: https://github.com/codementordev/cm_lograge_formatter
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.3'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.6.13
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Key Value formatter and no newline in value
|
64
|
+
test_files: []
|