rsstsvop 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6da5a86fe999285da2de9ed1fe4c5026bc576106
4
+ data.tar.gz: a18384ca890526b5dbe4c1939c2d8ed28d238a92
5
+ SHA512:
6
+ metadata.gz: 5b9acbe8be99d83c8619f110a1496ed784debd15cd0e0173a7c1a9b31bef03d021bad985c965b4ba5e31b622bf5cc9436f87a671330e15a2fdffaa38aed0e603
7
+ data.tar.gz: b79005d7aa86e3de0ff3b1538a4996650420795cbf269e92a4908c60c871916e80bfab14c1be55632e2b10f63f0a482fa5347b3bd92fba42f74ca48952d5e77f
data/.gitattributes ADDED
@@ -0,0 +1,21 @@
1
+ # Auto detect text files and perform LF normalization
2
+ #* text=auto
3
+
4
+ # 空白文字でくぎられる。前後の空白文字は無視される。
5
+ # #で始まる行は無視される。
6
+ # patternがパスに合致すれば、attributeが与えられる。
7
+ # パスが複数のpatternに合致すれば、最後のpatternが適用される。
8
+ # pattern matchは.gitignoreと同じ(ただし、否定ぱたーんは許されない。でぃれくとりに合致するぱたーんんは再帰的に適用されない
9
+ # pattern attr1 attr2 ...
10
+
11
+ # 後方互換性 crlfは以下のように解釈される
12
+ # crlf text
13
+ # -crlf -text
14
+ # crlf=input eolf=lf
15
+
16
+ # 例
17
+ # * text=auto
18
+ # *.txt text
19
+ # *.vcproj text eol=crlf
20
+ # *.sh text eol=lf
21
+ # *.jpg -text
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ desc/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ykominami@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rsstsvop.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 yasuo kominami
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Rsstsvop
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/rsstsvop`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rsstsvop'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rsstsvop
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ykominami/rsstsvop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Rsstsvop project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ykominami/rsstsvop/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rsstsvop"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rss ADDED
@@ -0,0 +1,91 @@
1
+ require 'rss'
2
+ require 'open-uri'
3
+ require 'pp'
4
+
5
+ module Rssop
6
+ class Rssop
7
+ attr_reader :content
8
+
9
+ @@config = { 1 => { :url => "https://dev.toppers.jp/trac/tecs/report/1?asc=1&format=rss",
10
+ :user => "ykominami",
11
+ :passwd => "A.jWmslz",
12
+ :fname => "rss-tecsgen.xml",
13
+ },
14
+ 2 => { :url => "https://nlightsystem.com/trac/mypz/login?referer=%2Ftrac%2Fmypz%2Freport%2F1%3Fasc%3D1%26format%3Drss",
15
+ :user => "kominami",
16
+ :passwd => "genken1967",
17
+ :fname => "rss-mypz.xml",
18
+ },
19
+ 22 => { :url => "https://nlightsystem.com/trac/mypz/login?referer=%2Ftrac%2Fmypz%2Freport%2F1%3Fasc%3D1%26format%3Drss",
20
+ :user => "kominami",
21
+ :passwd => "genken1967",
22
+ :fname => "rss-mypz-2.xml",
23
+ },
24
+ }
25
+ def initialize( index )
26
+ hash = @@config[index]
27
+ pp hash
28
+ @url = hash[:url]
29
+ @user = hash[:user]
30
+ @passwd = hash[:passwd]
31
+ @fname = hash[:fname]
32
+ end
33
+
34
+ def get
35
+ if @user != nil and @passwd != nil
36
+ @content = open(@url, http_basic_authentication: [@user, @passwd]).read
37
+ else
38
+ @content = open(@url).read
39
+ end
40
+
41
+ self
42
+ end
43
+
44
+ def save
45
+ File.open( @fname , 'w' , {encoding: Encoding::UTF_8} ){|f|
46
+ f.write( @content )
47
+ }
48
+
49
+ self
50
+ end
51
+
52
+ def read_from_file
53
+ File.open( @fname , 'r' , {encoding: Encoding::UTF_8} ){|f|
54
+ @content = f.read
55
+ }
56
+
57
+ self
58
+ end
59
+
60
+ def parse( validation=true )
61
+ @rss = RSS::Parser.parse(@content,validation)
62
+
63
+ self
64
+ end
65
+
66
+ def print_title_list
67
+ @rss.channel.items.each do |x|
68
+ puts x.title
69
+ end
70
+ end
71
+
72
+ def print_all_items
73
+ @rss.items.map{|item|
74
+ puts item.pubDate.strftime( "%Y/%m/%d" )
75
+ puts item.category.content
76
+ puts item.title
77
+ puts item.link
78
+ puts item.description
79
+ puts
80
+ }
81
+ end
82
+ end
83
+ end
84
+
85
+ #rssop = Rssop::Rssop.new(2)
86
+ #rssop.get.save.parse.print_title_list
87
+ rssop = Rssop::Rssop.new(22)
88
+ rssop.get.save.parse(false).print_all_items
89
+ #rssop.read_from_file.parse(false).print_title_list
90
+ #rssop.read_from_file.parse(false).print_all_items
91
+
data/bin/rsstsvop ADDED
@@ -0,0 +1,61 @@
1
+ require 'rsstsvop'
2
+ require 'yaml'
3
+
4
+ require 'simpleoptparse'
5
+
6
+ homedir = ENV['HOME']
7
+ homedir ||= ENV['USERPROFILE']
8
+
9
+ yamlfile_pn = Pathname.new( homedir ) / 'env-rsstsvop.yaml'
10
+
11
+ opts = { "yaml" => yamlfile_pn }
12
+ banner = "Usage: bundle exec ruby bin/rsstsvop [-f|--forced] [--rss|--tsv] [--yaml=yamlfile] index"
13
+
14
+ Simpleoptparse::Simpleoptparse.parse( ARGV , opts , banner , Rsstsvop::VERSION , nil ){ |parser|
15
+ parser.on('-f' , '--forced' ) { |x| opts["forced"] = true }
16
+ parser.on('--yaml=yamlfile' ) { |x| opts["yaml"] = Pathname.new(x) }
17
+ parser.on('--rss' ) { |x|
18
+ if opts["kind"]
19
+ opts["kind"] = :error
20
+ else
21
+ opts["kind"] = :rss
22
+ end
23
+ }
24
+ parser.on('--tsv' ) { |x|
25
+ if opts["kind"]
26
+ opts["kind"] = :error
27
+ else
28
+ opts["kind"] = :tsv
29
+ end
30
+ }
31
+ }
32
+
33
+ if ( opts["kind"] == nil or opts["kind"] == :error ) or ARGV.size != 1
34
+ puts banner
35
+ exit 10
36
+ else
37
+ opts["index"] = ARGV.pop.to_i
38
+ end
39
+
40
+ if opts["kind"] == :rss
41
+ rssop = Rsstsvop::Rssop.new( opts["index"] , opts["yaml"] )
42
+ if opts["forced"] or (File.exist?(rssop.fname) == false)
43
+ rssop.get.save
44
+ end
45
+ rssop.read_from_file.parse.print_all_items
46
+ else
47
+ tsvop = Rsstsvop::Tsvop.new( opts["index"] , opts["yaml"] )
48
+ if opts["forced"] or (File.exist?(tsvop.fname) == false)
49
+ tsvop.get.save
50
+ end
51
+ tsvop.read_from_file_to_array.parse.print_table( "desc" )
52
+ #tsvop.read_from_file.parse.print_by_component
53
+ #tsvop.read_from_file_to_array.parse.print_key
54
+ #tsvop.read_from_file_to_array.parse.print_by_component
55
+ #tsvop.read_from_file_to_array.parse.print_by_version
56
+ #tsvop.read_from_file_to_array.parse.print_by_milestone
57
+ #tsvop.read_from_file_to_array.parse.print_by_type
58
+ #tsvop.read_from_file_to_array.parse.print_by_owner
59
+ #tsvop.read_from_file_to_array.parse.print_by_status
60
+ #tsvop.read_from_file_to_array.parse.print_by_reporter
61
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/tsv ADDED
@@ -0,0 +1,32 @@
1
+ require 'rsstsvop'
2
+ require 'yaml'
3
+
4
+ require 'simpleoptparse'
5
+
6
+ homedir = ENV['HOME']
7
+ homedir ||= ENV['USERPROFILE']
8
+
9
+ opts = { db_dir: Arxutils::Dbutil::DB_DIR }
10
+ banner = "Usage: bundle exec ruby bin/tsv [--rss|--tsv] [--yaml=yamlfile] index"
11
+
12
+ if ARGV.size > 1
13
+ token = ARGV.shift
14
+ url = ARGV.shift
15
+ else
16
+ puts banner
17
+ exit 10
18
+ end
19
+
20
+ # wop = Simpleoptparse::Simpleoptparse.create( ARGV , opts , banner , Arxutils::
21
+ #p Simpleoptparse::Simpleoptparse.class
22
+ Simpleoptparse::Simpleoptparse.parse( ARGV , opts , banner , Rsstsvop::VERSION , nil ){ |parser|
23
+ parser.on('--yaml=yamlfile' ) { |x| opts["yaml] = x }
24
+ parser.on('--sqlite3' ) { |x| opts["dbconfig"] = Arxutils::Dbutil::DBCONFIG_SQLITE3 }
25
+ }
26
+
27
+ opts["dbconfig"] = Arxutils::Dbutil::DBCONFIG_SQLITE3 unless opts["dbconfig"]
28
+
29
+ tsvop = Rsstsvop::Tsvop.new(23)
30
+ #Rsstsvop::Tsvop.arg_parse( ARGV )
31
+ exit
32
+
data/lib/rsstsvop.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "rsstsvop/version"
2
+ require "rsstsvop/rsstsvop"
3
+ require "rsstsvop/tsvop"
4
+ require "rsstsvop/rssop"
5
+ require "pp"
6
+
7
+ module Rsstsvop
8
+ end
@@ -0,0 +1,73 @@
1
+ require 'rss'
2
+
3
+ module Rssop
4
+ class Rssop
5
+ attr_reader :content
6
+
7
+ def initialize( index )
8
+ hash = @@config[index]
9
+ pp hash
10
+ @url = hash[:url]
11
+ @user = hash[:user]
12
+ @passwd = hash[:passwd]
13
+ @fname = hash[:fname]
14
+ end
15
+
16
+ def get
17
+ if @user != nil and @passwd != nil
18
+ @content = open(@url, http_basic_authentication: [@user, @passwd]).read
19
+ else
20
+ @content = open(@url).read
21
+ end
22
+
23
+ self
24
+ end
25
+
26
+ def save
27
+ File.open( @fname , 'w' , {encoding: Encoding::UTF_8} ){|f|
28
+ f.write( @content )
29
+ }
30
+
31
+ self
32
+ end
33
+
34
+ def read_from_file
35
+ File.open( @fname , 'r' , {encoding: Encoding::UTF_8} ){|f|
36
+ @content = f.read
37
+ }
38
+
39
+ self
40
+ end
41
+
42
+ def parse( validation=true )
43
+ @rss = RSS::Parser.parse(@content,validation)
44
+
45
+ self
46
+ end
47
+
48
+ def print_title_list
49
+ @rss.channel.items.each do |x|
50
+ puts x.title
51
+ end
52
+ end
53
+
54
+ def print_all_items
55
+ @rss.items.map{|item|
56
+ puts item.pubDate.strftime( "%Y/%m/%d" )
57
+ puts item.category.content
58
+ puts item.title
59
+ puts item.link
60
+ puts item.description
61
+ puts
62
+ }
63
+ end
64
+ end
65
+ end
66
+
67
+ #rssop = Rssop::Rssop.new(2)
68
+ #rssop.get.save.parse.print_title_list
69
+ rssop = Rssop::Rssop.new(22)
70
+ rssop.get.save.parse(false).print_all_items
71
+ #rssop.read_from_file.parse(false).print_title_list
72
+ #rssop.read_from_file.parse(false).print_all_items
73
+
@@ -0,0 +1,36 @@
1
+ require 'rss'
2
+
3
+ module Rsstsvop
4
+ class Rssop < Rsstsvop
5
+
6
+ def initialize( index , yaml_pn )
7
+ yaml_data = load_yaml( yaml_pn )
8
+ super( yaml_data["rss"][index] )
9
+ end
10
+
11
+ def parse( validation=false )
12
+ @rss = RSS::Parser.parse(@content,validation)
13
+
14
+ self
15
+ end
16
+
17
+ def print_title_list
18
+ @rss.channel.items.each do |x|
19
+ puts x.title
20
+ end
21
+ end
22
+
23
+ def print_all_items
24
+ @rss.items.map{|item|
25
+ puts item.pubDate.strftime( "%Y/%m/%d" )
26
+ puts item.category.content
27
+ puts item.title
28
+ puts item.link
29
+ puts item.description
30
+ puts
31
+ }
32
+ end
33
+ end
34
+ end
35
+
36
+
@@ -0,0 +1,57 @@
1
+ require 'open-uri'
2
+ require 'yaml'
3
+
4
+ module Rsstsvop
5
+ class Rsstsvop
6
+ attr_reader :content , :content_array, :url, :user, :passwd, :fname
7
+
8
+ def initialize( hash )
9
+ @url = hash["url"]
10
+ @user = hash["user"]
11
+ @passwd = hash["passwd"]
12
+ @fname = hash["fname"]
13
+ end
14
+
15
+ def load_yaml( pn )
16
+ YAML.load_file( pn )
17
+ end
18
+
19
+ def get
20
+ if @user != nil and @passwd != nil
21
+ @content = open(@url, http_basic_authentication: [@user, @passwd]).read
22
+ else
23
+ @content = open(@url).read
24
+ end
25
+
26
+ self
27
+ end
28
+
29
+ def save
30
+ # puts "== save"
31
+ File.open( @fname , 'w' , {encoding: Encoding::UTF_8} ){|f|
32
+ f.write( @content )
33
+ }
34
+
35
+ self
36
+ end
37
+
38
+ def read_from_file
39
+ File.open( @fname , 'r' , {encoding: Encoding::UTF_8} ){|f|
40
+ @content = f.read
41
+ }
42
+ self
43
+ end
44
+
45
+ def read_from_file_to_array
46
+ @content_array = []
47
+ File.open( @fname , 'r' , {encoding: 'BOM|UTF-8'} ){|f|
48
+ while l = f.gets
49
+ @content_array << l.chomp!
50
+ end
51
+ }
52
+
53
+ self
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,186 @@
1
+ require 'csv'
2
+
3
+ module Rsstsvop
4
+ class Tsvop < Rsstsvop
5
+
6
+ def initialize( index , yaml_pn )
7
+ yaml_data = load_yaml( yaml_pn )
8
+ super( yaml_data["tsv"][index] )
9
+ end
10
+
11
+ def csv_pars_sub(fields , x)
12
+ if fields.size > @headers.size
13
+ puts "error 1!"
14
+ raise
15
+ elsif fields.size == @headers.size
16
+ if x.size != 0
17
+ puts "error 2!"
18
+ raise
19
+ else
20
+ hash = {}
21
+ 0.upto( fields.size - 1 ).each do |x|
22
+ hash[ @headers[x] ] = fields[x]
23
+ end
24
+ @parsed_data << hash
25
+ end
26
+ else
27
+ hash = {}
28
+ 0.upto( fields.size - 1 ).each do |x|
29
+ hash[ @headers[x] ] = fields[x]
30
+ end
31
+
32
+ tail_line = x.pop
33
+ tail_fields = tail_line.split("\t")
34
+ case tail_fields.size
35
+ when 1
36
+ hash[ @headers.last ] = tail_fields[0]
37
+ hash[ @headers[-2] ] = x.join("\n")
38
+ when 2
39
+ hash[ @headers.last ] = tail_fields.last
40
+ x.push( tail_fields[0] )
41
+ hash[ @headers[-2] ] = x.join("\n")
42
+ else
43
+ hash[ @headers.last ] = tail_fields.last
44
+ val , tmp = tail_line.split( "\t#{tail_fields.last}" )
45
+ x.push( val )
46
+ hash[ @headers[-2] ] = x.join("\n")
47
+ end
48
+
49
+ @parsed_data << hash
50
+ end
51
+ end
52
+
53
+ def csv_parse( array , **options )
54
+ @parsed_data = []
55
+ rows = []
56
+ data_rows = array
57
+ @headers = data_rows.shift.split("\t")
58
+
59
+ item_lines = nil
60
+ data_rows.each do |x|
61
+ if x =~ /^[[:digit:]]+\t/
62
+ rows << item_lines if item_lines
63
+ item_lines = []
64
+ else
65
+ # puts x
66
+ end
67
+ if item_lines == nil
68
+ puts x
69
+ puts "error a1"
70
+ raise
71
+ end
72
+ item_lines << x
73
+ end
74
+ rows << item_lines if item_lines.size > 0
75
+
76
+ cnt=0
77
+ rows.map{ |x2|
78
+ cnt += 1
79
+ fields = x2.shift.split("\t")
80
+ csv_pars_sub(fields , x2)
81
+ }
82
+
83
+ @parsed_data
84
+ end
85
+
86
+ def parse
87
+ # headers of tsv file
88
+ #
89
+ # ticket summary component version milestone type owner status created _changetime _description _reporter
90
+ @items_by_id = {}
91
+ @items_by_component = {}
92
+ @items_by_version = {}
93
+ @items_by_milestone = {}
94
+ @items_by_type = {}
95
+ @items_by_owner = {}
96
+ @items_by_status = {}
97
+ @items_by_reporter = {}
98
+
99
+ # @csv_data = CSV.parse( @content , { :headers => true } )
100
+ @csv_data = csv_parse( @content_array , { :headers => true } )
101
+
102
+ @csv_data.each do |data|
103
+ @items_by_id[ data['ticket'] ] = data
104
+ end
105
+
106
+ self
107
+ end
108
+
109
+ def setup_data( hash , key )
110
+ if hash.size == 0
111
+ @csv_data.each do |data|
112
+ hash[ data[key] ] ||= []
113
+ hash[ data[key] ] << data
114
+ end
115
+ end
116
+ end
117
+
118
+ def print_key_values( hash , id_key )
119
+ hash.each do |k,v|
120
+ puts "* #{k}"
121
+ puts v.map{|x| sprintf("#%s" , x[ id_key ]) }.join(",")
122
+ end
123
+ end
124
+
125
+ def print_by_component( )
126
+ setup_data( @items_by_component , 'component' )
127
+ print_key_values( @items_by_component , "ticket" )
128
+ end
129
+
130
+ def print_by_version
131
+ setup_data( @items_by_version , 'version' )
132
+ print_key_values( @items_by_version , "ticket" )
133
+ end
134
+
135
+ def print_by_milestone
136
+ setup_data( @items_by_milestone , 'milestorn' )
137
+ print_key_values( @items_by_milestone , "ticket" )
138
+ end
139
+
140
+ def print_by_type
141
+ setup_data( @items_by_type , 'type' )
142
+ print_key_values( @items_by_type , "ticket" )
143
+ end
144
+
145
+ def print_by_owner
146
+ setup_data( @items_by_owner , 'owner' )
147
+ print_key_values( @items_by_owner , "ticket" )
148
+ end
149
+
150
+ def print_by_status
151
+ setup_data( @items_by_status , 'statur' )
152
+ print_key_values( @items_by_status , "ticket" )
153
+ end
154
+
155
+ def print_by_reporter
156
+ setup_data( @items_by_reporter , 'reporter' )
157
+ print_key_values( @items_by_reporter , "ticket" )
158
+ end
159
+
160
+ def print_table( dir )
161
+ dirpn = Pathname.new(dir)
162
+ if dirpn.exist?
163
+ dirpn.rmtree
164
+ end
165
+ dirpn.mkdir
166
+ fields = %W!ticket summary component version milestone type owner status created _changetime _reporter!
167
+ table = @items_by_id.map{ |k,v|
168
+ (dirpn / (v["ticket"] + ".txt")).write( v["_description"] )
169
+ fields.map{|x| v[x]}.join("\t")
170
+ }.join("\n")
171
+ puts table
172
+ end
173
+
174
+ def print_key # for debug
175
+ puts "print_key"
176
+ @items_by_component.each do |k,v|
177
+ puts "* #{k}"
178
+ if v and v[0] and v[0].keys
179
+ puts v[0].keys.join(",")
180
+ else
181
+ puts " - "
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,3 @@
1
+ module Rsstsvop
2
+ VERSION = "0.1.0"
3
+ end
data/rsstsvop.gemspec ADDED
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rsstsvop/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rsstsvop"
8
+ spec.version = Rsstsvop::VERSION
9
+ spec.authors = ["yasuo kominami"]
10
+ spec.email = ["ykominami@gmail.com"]
11
+
12
+ spec.summary = %q{get tsv file or rss via network and crate tables.}
13
+ spec.description = %q{get tsv file or rss via network and crate tables.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_runtime_dependency "simpleoptparse"
30
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsstsvop
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: 2018-08-06 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simpleoptparse
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: get tsv file or rss via network and crate tables.
70
+ email:
71
+ - ykominami@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitattributes"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/rss
87
+ - bin/rsstsvop
88
+ - bin/setup
89
+ - bin/tsv
90
+ - lib/rsstsvop.rb
91
+ - lib/rsstsvop/rss.rb
92
+ - lib/rsstsvop/rssop.rb
93
+ - lib/rsstsvop/rsstsvop.rb
94
+ - lib/rsstsvop/tsvop.rb
95
+ - lib/rsstsvop/version.rb
96
+ - rsstsvop.gemspec
97
+ homepage: ''
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: get tsv file or rss via network and crate tables.
121
+ test_files: []