diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..7df6516 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index c553ae9..a84c801 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,4 @@ 1. Блоки, лямбды, проки. 1. Гемы. 1. Метапрограммирование. + diff --git a/converter/.DS_Store b/converter/.DS_Store new file mode 100644 index 0000000..c46f10e Binary files /dev/null and b/converter/.DS_Store differ diff --git a/converter/Gemfile b/converter/Gemfile new file mode 100644 index 0000000..e796b23 --- /dev/null +++ b/converter/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +# Specify your gem's dependencies in converter.gemspec +gemspec diff --git a/converter/Gemfile.lock b/converter/Gemfile.lock new file mode 100644 index 0000000..352c827 --- /dev/null +++ b/converter/Gemfile.lock @@ -0,0 +1,20 @@ +PATH + remote: . + specs: + converter (0.1.0) + +GEM + remote: https://rubygems.org/ + specs: + rake (10.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + bundler (~> 1.17) + converter! + rake (~> 10.0) + +BUNDLED WITH + 1.17.3 diff --git a/converter/LICENSE.txt b/converter/LICENSE.txt new file mode 100644 index 0000000..2575cf2 --- /dev/null +++ b/converter/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 TODO: Write your name + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/converter/README.md b/converter/README.md new file mode 100644 index 0000000..4bc4db7 --- /dev/null +++ b/converter/README.md @@ -0,0 +1,39 @@ +# Converter + +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/converter`. To experiment with that code, run `bin/console` for an interactive prompt. + +TODO: Delete this and the text above, and describe your gem + +## Installation + +Add this line to your application's Gemfile: + +```ruby +gem 'converter' +``` + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install converter + +## Usage + +TODO: Write usage instructions here + +## Development + +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. + +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). + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/converter. + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). diff --git a/converter/Rakefile b/converter/Rakefile new file mode 100644 index 0000000..43022f7 --- /dev/null +++ b/converter/Rakefile @@ -0,0 +1,2 @@ +require "bundler/gem_tasks" +task :default => :spec diff --git a/converter/bin/.DS_Store b/converter/bin/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/converter/bin/.DS_Store differ diff --git a/converter/bin/console b/converter/bin/console new file mode 100755 index 0000000..fb90eca --- /dev/null +++ b/converter/bin/console @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +require "bundler/setup" +require "converter" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/converter/bin/setup b/converter/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/converter/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/converter/converter.gemspec b/converter/converter.gemspec new file mode 100644 index 0000000..d00d611 --- /dev/null +++ b/converter/converter.gemspec @@ -0,0 +1,38 @@ + +lib = File.expand_path("../lib", __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require "converter/version" + +Gem::Specification.new do |spec| + spec.name = "converter" + spec.version = Converter::VERSION + spec.authors = ["@egorles"] + + spec.summary = %q{Converter from RSS/ATOM/JSON to RSS/ATOM/JSON} + spec.homepage = "https://github.com/egorles" + spec.license = "MIT" + + # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' + # to allow pushing to a single host or delete this section to allow pushing to any host. + if spec.respond_to?(:metadata) + spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" + + spec.metadata["homepage_uri"] = spec.homepage + + else + raise "RubyGems 2.0 or newer is required to protect against " \ + "public gem pushes." + end + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + spec.add_development_dependency "bundler", "~> 1.17" + spec.add_development_dependency "rake", "~> 10.0" +end diff --git a/converter/exe/converter b/converter/exe/converter new file mode 100755 index 0000000..d596515 --- /dev/null +++ b/converter/exe/converter @@ -0,0 +1,49 @@ +#!/usr/bin/env ruby + +require "bundler/setup" +require "converter" +require "optparse" + +options = {} + +gem_spec = Gem::Specification::load("converter.gemspec") + +parser = OptionParser.new do |opt| + opt.banner = "Usage #{gem_spec.name} [options]" + opt.define_head gem_spec.summary + + opt.separator "" + + opt.on("-i", "--input [url]", String) do |input| + options[:input] = input + end + opt.on("-o", "--output-format [rss | json | atom]", String) do |output| + options[:output] = output + end + opt.on("-s", "--sort [asc | desc]", String) do |sort| + options[:sort] = sort + end + opt.on("-f", "--file-name [string]", String) do |file| + options[:file] = file + end + + opt.separator "" + + opt.on("-h", "--help", "Show this message") do |help| + puts opt + exit + end +end + +begin + parser.parse! + puts "The result is %s" % Converter.convert(options) + +rescue OptionParser::InvalidArgument => e + STDERR.puts %Q[#{e.message.capitalize}. Run "#{File.basename($0)}" --help for details.] + exit 1 +rescue KeyError + STDERR.puts %Q[Insufficient arguments. Run "#{File.basename($0)}" --help for details.] + exit 2 +end + diff --git a/converter/lib/.DS_Store b/converter/lib/.DS_Store new file mode 100644 index 0000000..14963f6 Binary files /dev/null and b/converter/lib/.DS_Store differ diff --git a/converter/lib/converter.rb b/converter/lib/converter.rb new file mode 100644 index 0000000..4019bbf --- /dev/null +++ b/converter/lib/converter.rb @@ -0,0 +1,38 @@ +require "converter/version" +require 'rss' +require 'json' + + + +module Converter + class Error < StandardError; end + # Your code goes here... + + def self.convert (options = {}) + input = options.fetch(:input) + output = options.fetch(:output) + sort = options.fetch(:sort) + file = options.fetch.(:file) + + if (input.include? 'rss') + rss_read (input) + elsif (input.include? 'json') + json_read (input) + elsif (input.include? 'atom') + atom_read (input) + end + + end + + def self.rss_read (input) + url = "#{input}" + open(url) do |rss| + feed = RSS::Parser.parse(rss) + puts feed + end + end + + def self.json_read (input) + file = File.read(input) + end +end diff --git a/converter/lib/converter/version.rb b/converter/lib/converter/version.rb new file mode 100644 index 0000000..a1b66a2 --- /dev/null +++ b/converter/lib/converter/version.rb @@ -0,0 +1,3 @@ +module Converter + VERSION = "0.1.0" +end