class MediumExport::ArticlesFilter

Attributes

articles[R]
shell[R]

Public Class Methods

new(articles:, shell:) click to toggle source
# File lib/middleman-medium_export/articles_filter.rb, line 4
def initialize(articles:, shell:)
  @articles = articles
  @shell = shell
end

Public Instance Methods

all() click to toggle source
# File lib/middleman-medium_export/articles_filter.rb, line 13
def all
  articles
end
interactive() click to toggle source
# File lib/middleman-medium_export/articles_filter.rb, line 17
def interactive
  articles.each_with_object([]) do |article, acc|
    case ask_to_include(article.title)
      when 'Y' then acc.push(article)
      when 'S' then acc.push(article) and break(acc)
      when 'Q' then break(acc)
    end
  end
end
last() click to toggle source
# File lib/middleman-medium_export/articles_filter.rb, line 9
def last
  [articles.first]
end

Private Instance Methods

ask_to_include(title) click to toggle source
# File lib/middleman-medium_export/articles_filter.rb, line 29
def ask_to_include(title)
  shell.say(%Q(Do you want to publish "#{title}"\n).freeze)
  shell.say("  Y - yes and continue\n  S - yes and quit".freeze, :green)
  shell.say("  N - no and continue\n  Q - no and quit\n".freeze, :red)

  shell.ask("\n ", :magenta, limited_to: %w(Y S N Q).freeze)
end