Class: VideoSeoCheckService

Inherits:
Object
  • Object
show all
Defined in:
app/services/video_seo_check_service.rb

Overview

Service object: video seo check service.

Constant Summary collapse

SEO_TITLE_MIN_LENGTH =

SEO constants - fallback if not loaded from initializer

50
SEO_TITLE_MAX_LENGTH =

Seo title max length.

65
TITLE_MAX_LENGTH =

Title max length.

150
SEO_META_DESCRIPTION_MIN_LENGTH =

Seo meta description min length.

120
SEO_META_DESCRIPTION_MAX_LENGTH =

Seo meta description max length.

155
SEO_SUB_HEADER_MIN_LENGTH =

Seo sub header min length.

50
SEO_SUB_HEADER_MAX_LENGTH =

Seo sub header max length.

70

Instance Method Summary collapse

Constructor Details

#initialize(video) ⇒ VideoSeoCheckService

Returns a new instance of VideoSeoCheckService.



19
20
21
# File 'app/services/video_seo_check_service.rb', line 19

def initialize(video)
  @video = video
end

Instance Method Details

#analyze_seo_healthObject

Returns a hash of all SEO health check results



24
25
26
27
28
29
30
31
# File 'app/services/video_seo_check_service.rb', line 24

def analyze_seo_health
  {
    meta_title: meta_title_quality_status,
    meta_description: meta_description_quality_status,
    sub_header: sub_header_quality_status,
    expanded_description: expanded_description_quality_status
  }
end

#detailed_analysisObject

Returns detailed analysis with character counts and recommendations



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/services/video_seo_check_service.rb', line 66

def detailed_analysis
  {
    meta_title: {
      status: meta_title_quality_status,
      current_length: @video.meta_title&.length || 0,
      min_length: SEO_TITLE_MIN_LENGTH,
      max_length: SEO_TITLE_MAX_LENGTH,
      recommendation: meta_title_recommendation
    },
    meta_description: {
      status: meta_description_quality_status,
      current_length: @video.meta_description&.length || 0,
      min_length: SEO_META_DESCRIPTION_MIN_LENGTH,
      max_length: SEO_META_DESCRIPTION_MAX_LENGTH,
      recommendation: meta_description_recommendation
    },
    sub_header: {
      status: sub_header_quality_status,
      current_length: @video.sub_header&.length || 0,
      min_length: SEO_SUB_HEADER_MIN_LENGTH,
      max_length: SEO_SUB_HEADER_MAX_LENGTH,
      recommendation: sub_header_recommendation
    },
    expanded_description: {
      status: expanded_description_quality_status,
      current_length: @video.expanded_description&.length || 0,
      min_length: 200,
      max_length: 1000,
      recommendation: expanded_description_recommendation
    }
  }
end

#expanded_description_quality_statusObject

Returns individual status for expanded description



58
59
60
61
62
63
# File 'app/services/video_seo_check_service.rb', line 58

def expanded_description_quality_status
  return 'missing' if @video.expanded_description.blank?
  return 'poor' if @video.expanded_description.length < 200 || @video.expanded_description.length > 1000

  'good'
end

#meta_description_quality_statusObject

Returns individual status for meta description



42
43
44
45
46
47
# File 'app/services/video_seo_check_service.rb', line 42

def meta_description_quality_status
  return 'missing' if @video.meta_description.blank?
  return 'poor' if @video.meta_description.length < SEO_META_DESCRIPTION_MIN_LENGTH || @video.meta_description.length > SEO_META_DESCRIPTION_MAX_LENGTH

  'good'
end

#meta_title_quality_statusObject

Returns individual status for meta title



34
35
36
37
38
39
# File 'app/services/video_seo_check_service.rb', line 34

def meta_title_quality_status
  return 'missing' if @video.meta_title.blank?
  return 'poor' if @video.meta_title.length < SEO_TITLE_MIN_LENGTH || @video.meta_title.length > SEO_TITLE_MAX_LENGTH

  'good'
end

#sub_header_quality_statusObject

Returns individual status for sub header



50
51
52
53
54
55
# File 'app/services/video_seo_check_service.rb', line 50

def sub_header_quality_status
  return 'missing' if @video.sub_header.blank?
  return 'poor' if @video.sub_header.length < SEO_SUB_HEADER_MIN_LENGTH || @video.sub_header.length > SEO_SUB_HEADER_MAX_LENGTH

  'good'
end