Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
machine:
ruby:
version: 2.4.1
test:
post:
- bundle exec rubocop
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

ruby '> 2.4'
ruby '~> 2'

gem 'rspec'
gem 'rubocop'
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DEPENDENCIES
rubocop

RUBY VERSION
ruby 2.4.1p111
ruby 2.4.0p0

BUNDLED WITH
1.15.4
1.16.1
34 changes: 30 additions & 4 deletions lesson1.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
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
date_parts = birthday.split('/').reverse.map(&:to_i)
now = Time.now
birthday = Time.local(*date_parts)
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 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
# TODO
name = gets.chomp
last_name = gets.chomp
soname = gets.chomp
p "Hello #{name} #{last_name} #{soname}!"
end
end
43 changes: 29 additions & 14 deletions my_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(&: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
2 changes: 1 addition & 1 deletion spec/lesson1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down