ykutils 0.1.0

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.
@@ -0,0 +1,33 @@
1
+ require 'ykutils/debugutils'
2
+ require 'ykutils/stext'
3
+ require 'ykutils/xlines'
4
+
5
+ module Ykutils
6
+ class StructuredTextForX < StructuredText
7
+ include DebugUtils
8
+
9
+ def initialize( debug = false )
10
+ super()
11
+
12
+ debug_utils_init
13
+ set_debug( debug )
14
+ ends
15
+
16
+ def analyze( line_ary , fname = nil )
17
+ lines = XLines.new( line_ary )
18
+ # lines.output_f( fname )
19
+
20
+ analyze_sub( lines )
21
+ end
22
+
23
+ def analyze_sub( lines )
24
+ puts_current_method
25
+
26
+ while line = lines.get_line
27
+ # p line
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,125 @@
1
+ module Ykutils
2
+ module StringUtils
3
+
4
+ def nil_to_nullstring( str )
5
+ str ? str : ""
6
+ end
7
+
8
+ def get_basename_ext( it )
9
+ bn0 = it.basename.to_s
10
+ if RUBY_VERSION > "1.9"
11
+ # bn0.encode!( "internal" )
12
+ bn0.encode! "UTF-8"
13
+
14
+ end
15
+ list = bn0.split(".")
16
+ case list.size
17
+ when 0
18
+ bname = ""
19
+ ext = ""
20
+ when 1
21
+ bname = list[0]
22
+ ext = ""
23
+ when 2
24
+ bname = list[0]
25
+ ext = list[1]
26
+ else
27
+ bname_size = list.size - 1
28
+ bname = list[0,bname_size].join('.')
29
+ ext = list[-1]
30
+ end
31
+ [bname , ext]
32
+ end
33
+
34
+
35
+ def normal_string?( str )
36
+ ret = false
37
+ if str
38
+ s = str.strip
39
+ if s != ""
40
+ if s =~ /^[0-9A-Za-z_:\.\/\-]+$/
41
+ ret = true
42
+ end
43
+ end
44
+ end
45
+ ret
46
+ end
47
+
48
+ def get_normalized_string( str )
49
+ ret = ""
50
+ if str
51
+ ret = str.strip
52
+ end
53
+ ret
54
+ end
55
+
56
+ def make_content_from_template( template_ary , tag_value_hash , separator )
57
+ content_ary = []
58
+
59
+ reg_hash = { }
60
+ tag_value_hash.each do |k,v|
61
+ reg_hash[k] = Regexp.new( separator + k + separator )
62
+ end
63
+
64
+ template_ary.each do |line|
65
+ reg_hash.each do |k,v|
66
+ line = line.sub( v , tag_value_hash[k] )
67
+ end
68
+ content_ary << line
69
+ end
70
+ content_ary
71
+ end
72
+
73
+ def indent(n)
74
+ n = 0 unless n
75
+ @indent_hash ||= { }
76
+ @indent_hash[n] ||= " " * n
77
+ @indent_hash[n]
78
+ end
79
+
80
+ def print_hier( data , level )
81
+ case data.class.to_s
82
+ when "Hash"
83
+ data.each do |k,v|
84
+ # puts "#{indent(level)}#{k}|#{v.class} #{if v.class.to_s == 'String' then v.size else '' end }"
85
+ # puts "#{indent(level)}#{k}|#{v.class}"
86
+ print_hier( v , level + 1 )
87
+ end
88
+ when "Array"
89
+ data.each do |v|
90
+ print_hier( v , level + 1 )
91
+ end
92
+ else
93
+ # puts "#{indent(level)}|#{data.class}"
94
+ end
95
+ end
96
+
97
+ def print_hier_2( data , level )
98
+ case data.class.to_s
99
+ when "Hash"
100
+ data.each do |k,v|
101
+ # puts "#{indent(level)}#{k}|#{v.class} #{if v.class.to_s == 'String' then v.size else '' end }"
102
+ str = "#{indent(level)}#{k}|#{v.class}"
103
+ if v.class == Array
104
+ num = v.size
105
+ str += ("|" + num.to_s )
106
+ if num > 1
107
+ str += "###################"
108
+ end
109
+ end
110
+ # puts str
111
+ if k != "group"
112
+ print_hier_2( v , level + 1 )
113
+ end
114
+ end
115
+ when "Array"
116
+ data.each do |v|
117
+ print_hier_2( v , level + 1 )
118
+ end
119
+ else
120
+ # puts "#{indent(level)}|#{data.class}"
121
+ end
122
+ end
123
+
124
+ end
125
+ end
@@ -0,0 +1,36 @@
1
+ require 'tsort'
2
+
3
+ module Ykytils
4
+ class TreeManager
5
+ include TSort
6
+
7
+ def initialize
8
+ @table = { }
9
+ end
10
+
11
+ def add( parent_name , name )
12
+ if parent_name
13
+ parent = @table[parent_name]
14
+ if parent
15
+ @table[parent_name] << name
16
+ else
17
+ @table[parent_name] = [name]
18
+ end
19
+ else
20
+ @table[name] = []
21
+ end
22
+ end
23
+
24
+ def tsort_each_child(node, &block)
25
+ ary = @table[node]
26
+ if ary
27
+ ary.each(&block)
28
+ end
29
+ end
30
+
31
+ def tsort_each_node( &block)
32
+ @table.keys.each(&block)
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,26 @@
1
+ require 'ykutils/treemanager'
2
+
3
+ module Ykutils
4
+ class TreeManager
5
+ def addTag( node_name , tag_name )
6
+ unless @tag
7
+ @tag = { }
8
+ end
9
+
10
+ unless @tag[node_name]
11
+ @tag[node_name] = [tag_name]
12
+ else
13
+ @tag[node_name] << tag_name
14
+ end
15
+
16
+ end
17
+
18
+ def getTag( node_name)
19
+ ret = nil
20
+ if @tag
21
+ ret = @tag[node_name]
22
+ end
23
+ ret
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Ykutils
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'ykutils/debugutils'
2
+ require 'ykutils/lines'
3
+
4
+ module Ykutils
5
+ class XLines < Lines
6
+ include DebugUtils
7
+
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ require 'debugutils'
2
+ require 'stextx'
3
+ require 'yamlop'
4
+
5
+ class YamlXOp < YamlOp
6
+ attr_accessor :yaml
7
+
8
+ include DebugUtils
9
+
10
+ def initialize( opt , args , debug )
11
+ debug_utils_init
12
+ set_debug( debug )
13
+ end
14
+
15
+ def load( fname )
16
+ # d_puts "3"
17
+ # puts_current_method
18
+
19
+ # d_puts "fname=#{fname}"
20
+ @fname = fname
21
+ # @pstext = StructuredTextForX.new
22
+ # puts "fname=#{fname}"
23
+ # @pstext.load_analyze( fname )
24
+ @yaml = load_yaml_file( fname )
25
+ end
26
+
27
+ def yaml2stext
28
+ yaml_str = YAML.dump( @yaml )
29
+ yaml_ary = yaml_str.split("\n")
30
+ @yamlstext = StructuredTextForAccount.new
31
+ @yamlstext.analyze( yaml_ary )
32
+ end
33
+
34
+ end
data/ykutils.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ykutils/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ykutils"
8
+ spec.version = Ykutils::VERSION
9
+ spec.authors = ["yasuo kominami"]
10
+ spec.email = ["ykominami@gmail.com"]
11
+
12
+ spec.summary = %q{utilty function created by yk.}
13
+ spec.description = %q{utilty function created by yk.}
14
+ spec.homepage = ""
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ if spec.respond_to?(:metadata)
22
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
23
+ end
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.9"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ykutils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yasuo kominami
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: utilty function created by yk.
42
+ email:
43
+ - ykominami@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .rspec
50
+ - .travis.yml
51
+ - Gemfile
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - lib/ykutils.rb
57
+ - lib/ykutils/debugutils.rb
58
+ - lib/ykutils/fileoputils2.rb
59
+ - lib/ykutils/filepermision.rb
60
+ - lib/ykutils/hasharray.rb
61
+ - lib/ykutils/lines.rb
62
+ - lib/ykutils/lsutils.rb
63
+ - lib/ykutils/nkfutil.rb
64
+ - lib/ykutils/nkfutil19.rb
65
+ - lib/ykutils/osutil.rb
66
+ - lib/ykutils/pathop.rb
67
+ - lib/ykutils/retcodex.rb
68
+ - lib/ykutils/specfileop.rb
69
+ - lib/ykutils/stext.rb
70
+ - lib/ykutils/stextx.rb
71
+ - lib/ykutils/stringutils.rb
72
+ - lib/ykutils/treemanager.rb
73
+ - lib/ykutils/treemanagera.rb
74
+ - lib/ykutils/version.rb
75
+ - lib/ykutils/xlines.rb
76
+ - lib/ykutils/yamlxop.rb
77
+ - ykutils.gemspec
78
+ homepage: ''
79
+ licenses: []
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: utilty function created by yk.
101
+ test_files: []