From 14851d41f52b780e9a85e337c2aecff10d8f6eaf Mon Sep 17 00:00:00 2001 From: luba Date: Fri, 19 Oct 2018 19:16:34 +0300 Subject: [PATCH 1/5] done! --- Gemfile | 2 +- Gemfile.lock | 4 ++-- lesson1.rb | 28 ++++++++++++++++++++++++---- my_array.rb | 43 +++++++++++++++++++++++++++++-------------- spec/lesson1_spec.rb | 2 +- 5 files changed, 57 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index 4e0d590..28cd5cf 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '> 2.4' +ruby '2.4.0' gem 'rspec' gem 'rubocop' diff --git a/Gemfile.lock b/Gemfile.lock index ae332f1..0e90cc1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -41,7 +41,7 @@ DEPENDENCIES rubocop RUBY VERSION - ruby 2.4.1p111 + ruby 2.4.0p0 BUNDLED WITH - 1.15.4 + 1.16.1 diff --git a/lesson1.rb b/lesson1.rb index 5f2c9a4..34353b3 100644 --- a/lesson1.rb +++ b/lesson1.rb @@ -1,14 +1,34 @@ -require 'date' class Lesson1 def sum(val = 0) - # TODO + arr = val.to_s.chars.map(&:to_i) + summ = 0 + arr.each { |el| summ += el } + summ end def age(birthday) - # TODO + ff = birthday.split('/').reverse.map(&:to_i) + now = Time.now + birthday = Time.local(*ff) + @secs = (now - birthday).round + age_converter + p "Я живу #{@years} года или #{@days} дней или #{@hours} + часов или #{@mins} минут или #{@secs} секунд" + rescue StandardError + 'Invalid Date Format' + end + + def age_converter + @mins = @secs / 60 + @hours = @mins / 60 + @days = @hours / 24 + @years = @days / 365 end def name - # TODO + name = gets.chomp + last_name = gets.chomp + soname = gets.chomp + p "Hello #{name} #{last_name} #{soname}!" end end diff --git a/my_array.rb b/my_array.rb index 5146e42..67e1174 100644 --- a/my_array.rb +++ b/my_array.rb @@ -6,58 +6,73 @@ def initialize(arr = []) end def size - # TODO + @array.size end def reverse - # TODO + @array.reverse! end def max - # TODO + @array.max end def min - # TODO + @array.min end def desc - # TODO + @array.sort!.reverse! end def asc - # TODO + @array.sort! end def odd - # TODO + @array.select { |x| x if x.odd? } end def multiple_to_three - # TODO + @array.select { |x| x if (x % 3).zero? } end def uniq - # TODO + @array.uniq! end def devide_on_ten - # TODO + @array.collect { |x| x.to_f / 10 } end def chars - # TODO + alphabet_str = ' abcdefghijklmnopqrstuvwxyz' + arr = [] + @array.each { |el| arr.push(alphabet_str[el].to_sym) } + arr end def switch - # TODO + index_min = @array.index(@array.min) + index_max = @array.index(@array.max) + arr = [] + @array.each { |el| arr.push(el) } + arr[index_min] = @array.max + arr[index_max] = @array.min + arr end def before_min - # TODO + return [] if @array.empty? + index_min = @array.index(@array.min) + @array[0...index_min] end def three_smallest - # TODO + # arr = @array.clone + # arr_smallest = [] + # arr_smallest.push(arr.delete(arr.min)). + # push(arr.delete(arr.min)).push(arr.delete(arr.min)) + @array.sort[0..2] end end diff --git a/spec/lesson1_spec.rb b/spec/lesson1_spec.rb index d32dba4..7be1494 100644 --- a/spec/lesson1_spec.rb +++ b/spec/lesson1_spec.rb @@ -9,7 +9,7 @@ end describe '#age' do - it { expect(subject.age('03/05/1990')).to include('25') } + it { expect(subject.age('03/05/1990')).to include('28') } it { expect(subject.age(nil)).to eql('Invalid Date Format') } end From 32a9f3b4ce175d6b9db353c02699b6bd55fec1c2 Mon Sep 17 00:00:00 2001 From: luba Date: Fri, 19 Oct 2018 19:40:17 +0300 Subject: [PATCH 2/5] trosku menshe gavnocoda --- lesson1.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lesson1.rb b/lesson1.rb index 34353b3..3a9b49d 100644 --- a/lesson1.rb +++ b/lesson1.rb @@ -10,19 +10,25 @@ def age(birthday) ff = birthday.split('/').reverse.map(&:to_i) now = Time.now birthday = Time.local(*ff) - @secs = (now - birthday).round - age_converter - p "Я живу #{@years} года или #{@days} дней или #{@hours} - часов или #{@mins} минут или #{@secs} секунд" + secs = (now - birthday).round + h = convert_age(secs) + p "Я живу #{h[:years]} года или #{h[:days]} дней или #{h[:hours]} + часов или #{h[:mins]} минут или #{secs} секунд" rescue StandardError 'Invalid Date Format' end - def age_converter - @mins = @secs / 60 - @hours = @mins / 60 - @days = @hours / 24 - @years = @days / 365 + def convert_age(secs) + mins = secs / 60 + hours = mins / 60 + days = hours / 24 + years = days / 365 + { + mins: mins, + hours: hours, + days: days, + years: years + } end def name From c7eacf006da0bc442af6075a9a5ceb79b8e0f8a5 Mon Sep 17 00:00:00 2001 From: "luba.t" Date: Fri, 19 Oct 2018 20:20:24 +0300 Subject: [PATCH 3/5] improve code --- lesson1.rb | 4 ++-- my_array.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lesson1.rb b/lesson1.rb index 3a9b49d..56a98e0 100644 --- a/lesson1.rb +++ b/lesson1.rb @@ -7,9 +7,9 @@ def sum(val = 0) end def age(birthday) - ff = birthday.split('/').reverse.map(&:to_i) + date_parts = birthday.split('/').reverse.map(&:to_i) now = Time.now - birthday = Time.local(*ff) + birthday = Time.local(*date_parts) secs = (now - birthday).round h = convert_age(secs) p "Я живу #{h[:years]} года или #{h[:days]} дней или #{h[:hours]} diff --git a/my_array.rb b/my_array.rb index 67e1174..c9ab4ab 100644 --- a/my_array.rb +++ b/my_array.rb @@ -22,15 +22,15 @@ def min end def desc - @array.sort!.reverse! + @array.sort.reverse end def asc - @array.sort! + @array.sort end def odd - @array.select { |x| x if x.odd? } + @array.select(&:odd?) end def multiple_to_three From 1bf3be276aec569f1c437a91e63c8216daf78e85 Mon Sep 17 00:00:00 2001 From: "luba.t" Date: Sun, 21 Oct 2018 12:11:41 +0300 Subject: [PATCH 4/5] update CI config --- .circleci/config.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 454ea6a..92dd57f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,5 +2,7 @@ machine: ruby: version: 2.4.1 test: - post: - - bundle exec rubocop + steps: + - checkout + - run: bundle exec rubocop + - run: bundle exec rspec \ No newline at end of file From 90f0d86469681c9bb04d740378f7b44c55dcad20 Mon Sep 17 00:00:00 2001 From: "luba.t" Date: Sun, 21 Oct 2018 12:44:59 +0300 Subject: [PATCH 5/5] update CI config --- .circleci/config.yml | 10 ++++++---- Gemfile | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 92dd57f..9a9eacf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,8 +1,10 @@ -machine: - ruby: - version: 2.4.1 -test: +jobs: + build: + docker: + - image: circleci/ruby:rc-browsers-legacy steps: - checkout + - run: gem install bundler + - run: bundle install - run: bundle exec rubocop - run: bundle exec rspec \ No newline at end of file diff --git a/Gemfile b/Gemfile index 28cd5cf..06f683f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.4.0' +ruby '~> 2' gem 'rspec' gem 'rubocop'