lucarecord 0.2.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +0 -0
- data/LICENSE +674 -0
- data/lib/luca_record.rb +7 -0
- data/lib/luca_record/base.rb +12 -0
- data/lib/luca_record/dict.rb +146 -0
- data/lib/luca_record/io.rb +337 -0
- data/lib/luca_record/version.rb +5 -0
- data/lib/luca_support.rb +19 -0
- data/lib/luca_support/code.rb +111 -0
- data/lib/luca_support/config.rb +11 -0
- data/lib/luca_support/mail.rb +44 -0
- data/lib/luca_support/view.rb +46 -0
- metadata +115 -0
data/lib/luca_support.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LucaSupport
|
4
|
+
autoload :Code, 'luca_support/code'
|
5
|
+
autoload :Config, 'luca_support/config'
|
6
|
+
autoload :Mail, 'luca_support/mail'
|
7
|
+
autoload :View, 'luca_support/view'
|
8
|
+
|
9
|
+
def self.match_score(a, b, n = 2)
|
10
|
+
v_a = to_ngram(a, n)
|
11
|
+
v_b = to_ngram(b, n)
|
12
|
+
|
13
|
+
v_a.map { |item| v_b.include?(item) ? 1 : 0 }.sum / v_a.length.to_f
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.to_ngram(str, n = 2)
|
17
|
+
str.each_char.each_cons(n).map(&:join)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'digest/sha1'
|
6
|
+
|
7
|
+
# implement Luca IDs convention
|
8
|
+
module LucaSupport
|
9
|
+
module Code
|
10
|
+
module_function
|
11
|
+
|
12
|
+
def encode_txid(num)
|
13
|
+
txmap = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
14
|
+
l = txmap.length
|
15
|
+
txmap[num / (l**2)] + txmap[(num%(l**2)) / l] + txmap[num % l]
|
16
|
+
end
|
17
|
+
|
18
|
+
def decode_txid(id)
|
19
|
+
txmap = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
20
|
+
l = txmap.length
|
21
|
+
txmap.index(id[0]) * (l**2) + txmap.index(id[1]) * l + txmap.index(id[2])
|
22
|
+
end
|
23
|
+
|
24
|
+
#
|
25
|
+
# Day of month to code conversion.
|
26
|
+
# Date, DateTime, String, Integer is valid input. If nil, returns empty String for consistency.
|
27
|
+
#
|
28
|
+
def encode_date(date)
|
29
|
+
return '' if date.nil?
|
30
|
+
|
31
|
+
index = date.day if date.respond_to?(:day)
|
32
|
+
index ||= date.to_i if date.respond_to?(:to_i)
|
33
|
+
index ||= 0
|
34
|
+
raise 'Invalid date specified' if index < 1 || index > 31
|
35
|
+
|
36
|
+
'0123456789ABCDEFGHIJKLMNOPQRSTUV'[index]
|
37
|
+
end
|
38
|
+
|
39
|
+
def decode_date(char)
|
40
|
+
'0123456789ABCDEFGHIJKLMNOPQRSTUV'.index(char)
|
41
|
+
end
|
42
|
+
|
43
|
+
def delimit_num(num)
|
44
|
+
num.to_s.reverse.gsub!(/(\d{3})(?=\d)/, '\1,').reverse!
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Month to code conversion.
|
49
|
+
# Date, DateTime, String, Integer is valid input. If nil, returns empty String for consistency.
|
50
|
+
#
|
51
|
+
def encode_month(date)
|
52
|
+
return '' if date.nil?
|
53
|
+
|
54
|
+
index = date.month if date.respond_to?(:month)
|
55
|
+
index ||= date.to_i if date.respond_to?(:to_i)
|
56
|
+
index ||= 0
|
57
|
+
raise 'Invalid month specified' if index < 1 || index > 12
|
58
|
+
|
59
|
+
'0ABCDEFGHIJKL'[index]
|
60
|
+
end
|
61
|
+
|
62
|
+
def decode_month(char)
|
63
|
+
'0ABCDEFGHIJKL'.index(char)
|
64
|
+
end
|
65
|
+
|
66
|
+
def decode_term(char)
|
67
|
+
m = /^([0-9]{4})([A-La-l])/.match(char)
|
68
|
+
[m[1].to_i, decode_month(m[2])]
|
69
|
+
end
|
70
|
+
|
71
|
+
def issue_random_id
|
72
|
+
Digest::SHA1.hexdigest(SecureRandom.uuid)
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# convert effective/defunct data into current hash on @date
|
77
|
+
#
|
78
|
+
def parse_current(dat)
|
79
|
+
{}.tap do |processed|
|
80
|
+
dat.each { |k, _v| processed[k] = take_current(dat, k) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# return current value with effective/defunct on target @date
|
86
|
+
# For multiple attribues, return hash on other than 'val'. Examples are as bellows:
|
87
|
+
#
|
88
|
+
# - effective: 2020-1-1
|
89
|
+
# val: 3000
|
90
|
+
# => 3000
|
91
|
+
#
|
92
|
+
# - effective: 2020-1-1
|
93
|
+
# rank: 5
|
94
|
+
# point: 1000
|
95
|
+
# => { 'effective' => 2020-1-1, 'rank' => 5, '' => 'point' => 1000 }
|
96
|
+
#
|
97
|
+
def take_current(dat, item)
|
98
|
+
target = dat.dig(item)
|
99
|
+
if target.class.name == 'Array' && target.map(&:keys).flatten.include?('effective')
|
100
|
+
latest = target
|
101
|
+
.filter { |a| Date.parse(a.dig('effective').to_s) < @date }
|
102
|
+
.max { |a, b| Date.parse(a.dig('effective').to_s) <=> Date.parse(b.dig('effective').to_s) }
|
103
|
+
return nil if !latest.dig('defunct').nil? && Date.parse(latest.dig('defunct').to_s) < @date
|
104
|
+
|
105
|
+
latest.dig('val') || latest
|
106
|
+
else
|
107
|
+
target
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "mail"
|
2
|
+
require "pathname"
|
3
|
+
require "luca_record/io"
|
4
|
+
|
5
|
+
module LucaSupport
|
6
|
+
class Mail
|
7
|
+
include LucaRecord::IO
|
8
|
+
|
9
|
+
def initialize(mail=nil, pjdir=nil)
|
10
|
+
@pjdir = pjdir || Dir.pwd
|
11
|
+
@config = load_config( Pathname(@pjdir) + "config.yml" )
|
12
|
+
@mail = mail
|
13
|
+
set_message_default
|
14
|
+
@host = set_host
|
15
|
+
end
|
16
|
+
|
17
|
+
def deliver
|
18
|
+
# mail gem accepts hash for 2nd param, not keywords
|
19
|
+
@mail.delivery_method(:smtp, @host)
|
20
|
+
@mail.deliver
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_host
|
24
|
+
{
|
25
|
+
authentication: :plain,
|
26
|
+
address: mail_config("address"),
|
27
|
+
port: mail_config("port"),
|
28
|
+
doomain: mail_config("domain"),
|
29
|
+
user_name: mail_config("user_name"),
|
30
|
+
password: mail_config("password")
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def mail_config(attr=nil)
|
35
|
+
return nil if attr.nil?
|
36
|
+
@config.dig("mail", attr)
|
37
|
+
end
|
38
|
+
|
39
|
+
def set_message_default
|
40
|
+
@mail.from ||= @config.dig("mail", "from")
|
41
|
+
@mail.cc ||= @config.dig("mail", "cc")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'open3'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
module LucaSupport
|
8
|
+
#
|
9
|
+
# File rendering functionality like HTML, PDF.
|
10
|
+
#
|
11
|
+
module View
|
12
|
+
module_function
|
13
|
+
|
14
|
+
def save_pdf(html_dat, path)
|
15
|
+
File.write(path, html2pdf(html_dat))
|
16
|
+
end
|
17
|
+
|
18
|
+
def erb2pdf(path)
|
19
|
+
html2pdf(render_erb(path))
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_erb(path)
|
23
|
+
@template_dir = File.dirname(path)
|
24
|
+
erb = ERB.new(File.read(path.to_s), trim_mode: '-')
|
25
|
+
erb.result(binding)
|
26
|
+
end
|
27
|
+
|
28
|
+
#
|
29
|
+
# Requires wkhtmltopdf command
|
30
|
+
#
|
31
|
+
def html2pdf(html_dat)
|
32
|
+
out, err, stat = Open3.capture3('wkhtmltopdf - -', stdin_data: html_dat)
|
33
|
+
puts err
|
34
|
+
out
|
35
|
+
end
|
36
|
+
|
37
|
+
def search_template(file, dir = 'templates')
|
38
|
+
# TODO: load config
|
39
|
+
[@pjdir, lib_path].each do |base|
|
40
|
+
path = (Pathname(base) / dir / file)
|
41
|
+
return path.to_path if path.file?
|
42
|
+
end
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lucarecord
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.13
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chuma Takahiro
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mail
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 12.3.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 12.3.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
description: 'ERP File operation framework
|
70
|
+
|
71
|
+
'
|
72
|
+
email:
|
73
|
+
- co.chuma@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- CHANGELOG.md
|
79
|
+
- LICENSE
|
80
|
+
- lib/luca_record.rb
|
81
|
+
- lib/luca_record/base.rb
|
82
|
+
- lib/luca_record/dict.rb
|
83
|
+
- lib/luca_record/io.rb
|
84
|
+
- lib/luca_record/version.rb
|
85
|
+
- lib/luca_support.rb
|
86
|
+
- lib/luca_support/code.rb
|
87
|
+
- lib/luca_support/config.rb
|
88
|
+
- lib/luca_support/mail.rb
|
89
|
+
- lib/luca_support/view.rb
|
90
|
+
homepage: https://github.com/chumaltd/luca/lucarecord
|
91
|
+
licenses: []
|
92
|
+
metadata:
|
93
|
+
homepage_uri: https://github.com/chumaltd/luca/lucarecord
|
94
|
+
source_code_uri: https://github.com/chumaltd/luca/lucarecord
|
95
|
+
changelog_uri: https://github.com/chumaltd/luca/lucarecord/CHANGELOG.md
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubygems_version: 3.1.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: ERP File operation framework
|
115
|
+
test_files: []
|